/* Smartphone layout. Linked with media="(max-width: 767px)", so desktop never applies these rules. */

/* ---------- Base ---------- */
body { padding: 10px; }
body.admin-compact { padding: 0; }

.container,
body.admin-compact .container {
    max-width: 100%;
    padding: 16px;
}

body.admin-compact .container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
}

h1 { font-size: 22px; }
h2 { font-size: 19px; }

/* iOS zooms into inputs below 16px. */
input,
select,
textarea,
body.admin-compact input,
body.admin-compact select,
body.admin-compact textarea {
    font-size: 16px !important;
    max-width: 100%;
}

button,
body.admin-compact button {
    min-height: 40px;
}

.btn-icon {
    min-width: 40px;
    min-height: 40px;
}

.nav-item:hover,
.btn-icon:hover {
    transform: none;
}

/* Inline flex rows from templates should wrap instead of overflowing. */
[style*="display: flex"],
[style*="display:flex"] {
    flex-wrap: wrap;
}

[style*="flex-grow: 1"] {
    flex-basis: 100%;
}

[style*="margin-left: auto"] {
    margin-left: 0 !important;
}

.btn-group {
    flex-wrap: wrap;
}

.btn-group button {
    flex: 1 1 auto;
}

/* ---------- Mobile-only controls ---------- */
.mobile-only {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.desktop-only {
    display: none !important;
}

.btn-add,
body.admin-compact button.btn-add {
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
    flex: 0 0 auto;
}

.mobile-filter-toggle {
    background: #fff;
    color: #0066CC;
    border: 2px solid #0066CC;
    white-space: nowrap;
}

.mobile-filter-toggle::after {
    content: ' ▾';
}

body.mobile-filters-open .mobile-filter-toggle {
    background: #0066CC;
    color: #fff;
}

body.mobile-filters-open .mobile-filter-toggle::after {
    content: ' ▴';
}

/* Collapsed: hide secondary filters and the sort/filter header chips. */
body:not(.mobile-filters-open) .mobile-filter-extra,
body:not(.mobile-filters-open) #playersTable > thead,
body:not(.mobile-filters-open) #sponsorsTableWrap table > thead,
body:not(.mobile-filters-open) .tabs .tab-btn:not(.active) {
    display: none !important;
}

/* ---------- Admin navigation ---------- */
.admin-nav {
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.nav-left {
    display: contents;
}

.nav-logo {
    width: 44px;
    height: 44px;
}

.nav-right {
    margin-left: auto;
    gap: 6px;
}

.nav-right .user-info {
    display: none;
}

.nav-toggle {
    display: flex !important;
}

.nav-menu {
    display: none;
    order: 3;
    width: 100%;
    flex-direction: column;
    gap: 4px;
}

.admin-nav.nav-open .nav-menu {
    display: flex;
}

.nav-item,
body.admin-compact .nav-item {
    padding: 12px 14px;
    font-size: 15px;
}

/* ---------- Forms ---------- */
.form-row,
.sp-form-grid {
    grid-template-columns: 1fr !important;
}

/* ---------- Modals: full screen ---------- */
.modal {
    align-items: stretch;
}

.modal-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 16px;
}

.modal-header {
    position: sticky;
    top: -16px;
    z-index: 2;
    background: #fff;
    padding: 8px 0;
    margin: -8px 0 12px;
}

.close-btn {
    width: 44px;
    height: 44px;
    font-size: 30px;
}

/* ---------- Tables as cards ---------- */
table,
table > tbody,
table > tfoot,
table > tbody > tr,
table > tfoot > tr,
table > thead {
    display: block;
    width: 100%;
}

table > thead > tr {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

table > thead > tr > th {
    display: block;
    width: auto !important;
    padding: 6px 10px !important;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    font-size: 13px;
    text-align: left !important;
}

/* Only keep header chips that sort or filter. */
table > thead > tr > th:not([onclick]):not([data-sort]):not(:has(button, input, select)) {
    display: none;
}

table > tbody > tr,
table > tfoot > tr {
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    padding: 6px 12px;
    margin-bottom: 10px;
    background: #fff;
}

table > tfoot > tr {
    background: #f8f9fa;
}

tr:hover {
    background: inherit;
}

table > tbody > tr > td,
table > tfoot > tr > td,
table > tfoot > tr > th {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 4px 12px;
    width: auto !important;
    padding: 6px 0 !important;
    border-top: none;
    border-right: none;
    border-bottom: 1px solid #f1f3f5;
    text-align: right !important;
}

table > tbody > tr > td:last-child,
table > tfoot > tr > :last-child {
    border-bottom: none;
}

table > tbody > tr > td[style*="border-left"] {
    padding-left: 8px !important;
}

table td[data-label]::before,
table tfoot th[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 13px;
    color: #6c757d;
    text-align: left;
    margin-right: auto;
}

table td[data-label=""]::before,
table tfoot th[data-label=""]::before {
    content: none;
}

table td[data-label=""] {
    justify-content: flex-start;
}

table td[colspan] {
    justify-content: center;
    text-align: center !important;
}

td button {
    margin-right: 0;
}

table > tbody > tr > td:empty {
    display: none;
}

/* Small modal tables fit on phones; keep them as real tables. */
table.sp-mini-table { display: table; }
.sp-mini-table > thead { display: table-header-group; }
.sp-mini-table > tbody { display: table-row-group; }
.sp-mini-table > tfoot { display: table-footer-group; }
.sp-mini-table > thead > tr,
.sp-mini-table > tbody > tr,
.sp-mini-table > tfoot > tr {
    display: table-row;
    border: none;
    padding: 0;
    margin: 0;
}
.sp-mini-table > thead > tr > th,
.sp-mini-table > tbody > tr > td,
.sp-mini-table > tfoot > tr > th,
.sp-mini-table > tfoot > tr > td {
    display: table-cell !important;
    padding: 6px 4px !important;
    border: none;
    border-bottom: 1px solid #eee;
    border-radius: 0;
    text-align: left !important;
    font-size: 13px;
}
.sp-mini-table td::before,
.sp-mini-table th::before {
    content: none !important;
}
.sp-mini-table td button {
    min-height: 36px;
}

/* Internal contacts: 6 columns are too wide, render each row as a compact list item. */
#contactsListTable,
#contactsListTable > tbody {
    display: block;
}

#contactsListTable > thead {
    display: none !important;
}

#contactsListTable > tbody > tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 2px 12px;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

#contactsListTable > tbody > tr > td {
    display: block !important;
    padding: 0 !important;
    border: none;
    font-size: 14px;
    min-width: 0;
    overflow-wrap: anywhere;
}

#contactsListTable > tbody > tr > td:nth-child(1) { grid-column: 1; grid-row: 1 / span 3; }
#contactsListTable > tbody > tr > td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 600; }
#contactsListTable > tbody > tr > td:nth-child(3) { grid-column: 2; grid-row: 2; color: #555; }
#contactsListTable > tbody > tr > td:nth-child(4) { grid-column: 2; grid-row: 3; color: #555; }
#contactsListTable > tbody > tr > td:nth-child(5) { grid-column: 3; grid-row: 1; text-align: right !important; }
#contactsListTable > tbody > tr > td:nth-child(6) { grid-column: 3; grid-row: 2 / span 2; }

#contactsListTable > tbody > tr > td[colspan] {
    grid-column: 1 / -1;
    grid-row: auto;
}

#contactsListTable > tbody > tr > td:empty {
    display: none !important;
}

/* ---------- Players ---------- */
.tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    flex-shrink: 0;
}

#searchInput {
    max-width: 100% !important;
}

#listSection [style*="flex-grow: 1"] {
    flex: 1 1 0;
    min-width: 0;
}

#listSection .mobile-filter-extra {
    order: 5;
    flex-basis: 100%;
}

#playersTable td:nth-child(2) {
    justify-content: flex-start;
    font-size: 16px;
}

#playersTable td:nth-child(2)::before {
    content: none;
}

#bulkActionsBar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}

#bulkActionsBar select {
    width: 100% !important;
}

body:has(#bulkActionsBar[style*="display: flex"]) .container {
    padding-bottom: 240px;
}

#teamFilterDropdown,
#plannedTeamFilterDropdown {
    max-width: calc(100vw - 32px);
}

/* ---------- Sponsors ---------- */
.sp-kpis {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
}

.sp-card {
    padding: 12px;
}

.sp-toolbar > input[type="search"],
.sp-toolbar > select {
    flex: 1 1 100%;
    width: 100% !important;
}

.sp-toolbar .sp-year-input {
    flex: 1 1 0;
    width: auto !important;
}

.sp-toolbar .sp-spacer {
    display: none;
}

.sp-toolbar .mobile-filter-toggle {
    flex: 1 1 auto;
}

#sponsorsTableWrap .sp-col-name {
    justify-content: flex-start;
    font-size: 16px;
    white-space: normal;
}

.sp-kpi-value {
    font-size: 20px !important;
}

#sponsorsTableWrap .sp-col-name::before {
    content: none;
}

#sponsorsTableWrap td.sp-has-note::after {
    content: attr(data-note);
    position: static;
    flex-basis: 100%;
    border: none;
    font-size: 12px;
    color: #8a5a00;
}

#sponsorsTableWrap td.sp-last-invoice[title]::after {
    content: attr(title);
    flex-basis: 100%;
    font-size: 12px;
    font-weight: 400;
    color: #6c757d;
}

.sp-inline-edit {
    flex: 1 1 100%;
    align-items: stretch;
}

.sp-inline-input,
.sp-inline-note,
.sp-inline-month,
.sp-inline input,
.sp-inline select {
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 100% !important;
}

/* ---------- Clubs / Plugins / Stats ---------- */
.stats-container {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 16px;
}

.stat-card {
    padding: 10px 6px;
}

.stat-card h3 {
    font-size: 10px;
    letter-spacing: 0;
}

.stat-card .stat-value {
    font-size: 22px;
}
.club-grid,
#pluginsGrid {
    grid-template-columns: 1fr !important;
}

.header-actions {
    flex-wrap: wrap;
    gap: 10px;
}

.header-actions > div {
    width: 100%;
}

.search-box {
    width: 100%;
    flex: 1 1 100%;
}

.stats-controls select {
    max-width: 100%;
    flex: 1 1 100%;
}

.bar-col {
    width: 56px;
}

.chart-card {
    padding: 12px;
}
