/*
 * AXO Control — modern layer. Loaded after app.css (and portal.css): same black/white theme, softer shapes,
 * better type, depth, motion and a complete mobile layout. Nothing here changes behaviour.
 */
@font-face { font-family: "Vazir"; font-weight: 300; font-display: swap; src: url("fonts/vazir-300.woff2") format("woff2"); }
@font-face { font-family: "Vazir"; font-weight: 400 500; font-display: swap; src: url("fonts/vazir-500.woff2") format("woff2"); }
@font-face { font-family: "Vazir"; font-weight: 600 800; font-display: swap; src: url("fonts/vazir-700.woff2") format("woff2"); }

:root {
    --radius: 14px;
    --radius-lg: 20px;
    --ring: 0 0 0 3px rgba(120, 169, 255, .28);
    --shadow-1: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 10px 30px rgba(0, 0, 0, .28);
    --shadow-2: 0 24px 70px rgba(0, 0, 0, .55);
    --ease: cubic-bezier(.2, .8, .2, 1);
    font-family: "Vazir", Tahoma, Arial, sans-serif;
}
html[data-theme="light"] {
    --ring: 0 0 0 3px rgba(47, 111, 209, .22);
    --shadow-1: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 8px 26px rgba(20, 30, 50, .07);
    --shadow-2: 0 24px 70px rgba(20, 30, 50, .18);
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-size: 14px; line-height: 1.7; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
    background:
        radial-gradient(900px 420px at 88% -8%, rgba(120, 169, 255, .075), transparent 60%),
        radial-gradient(700px 360px at 4% 0%, rgba(255, 255, 255, .035), transparent 60%),
        var(--bg);
    background-attachment: fixed;
}
html[data-theme="light"] body {
    background:
        radial-gradient(900px 420px at 88% -8%, rgba(47, 111, 209, .07), transparent 60%),
        radial-gradient(700px 360px at 4% 0%, rgba(0, 0, 0, .025), transparent 60%),
        var(--bg);
    background-attachment: fixed;
}
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 0; box-shadow: var(--ring); border-radius: 10px; }
::selection { background: rgba(120, 169, 255, .35); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---------- sidebar ---------- */
.sidebar { background: linear-gradient(180deg, #0f0f10, #0b0b0b); border-left-color: var(--line); padding: 22px 14px 16px; transition: transform .28s var(--ease); }
html[data-theme="light"] .sidebar { background: linear-gradient(180deg, #ffffff, #f8f9fb); }
.side-brand { padding: 2px 8px 22px; }
.side-brand strong { font-size: 16px; font-weight: 800; letter-spacing: .01em; }
.nav-item { min-height: 44px; border-radius: 12px; font-weight: 500; transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease); }
.nav-item:hover { transform: translateX(-2px); }
.nav-item.is-active { box-shadow: 0 8px 22px rgba(255, 255, 255, .12); }
html[data-theme="light"] .nav-item.is-active { box-shadow: 0 8px 22px rgba(20, 24, 28, .2); }
.nav-item b { border-radius: 999px; }
.side-status { border-radius: 14px; background: var(--surface); }
.logout-link { color: var(--muted); }
.logout-link:hover { color: var(--red); background: rgba(240, 107, 107, .08); }

/* ---------- top bar ---------- */
.main-content { padding: 0 clamp(16px, 3vw, 38px) 56px; }
.topbar {
    position: sticky; top: 0; z-index: 25; height: 84px; margin: 0 calc(-1 * clamp(16px, 3vw, 38px)) 26px; padding: 0 clamp(16px, 3vw, 38px);
    background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}
.page-title h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; transition: background .18s, border-color .18s, transform .18s var(--ease); }
.icon-btn:active { transform: scale(.94); }

/* ---------- buttons, fields ---------- */
.btn { min-height: 42px; border-radius: 12px; padding: 0 18px; font-weight: 600; transition: background .18s, border-color .18s, transform .18s var(--ease), box-shadow .18s; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-primary { box-shadow: 0 8px 22px rgba(255, 255, 255, .1); }
html[data-theme="light"] .btn-primary { box-shadow: 0 8px 22px rgba(20, 24, 28, .22); }
.btn-ghost, .btn-secondary { backdrop-filter: blur(6px); }
.field input, .field select, .field textarea, .search-box, .select-compact { border-radius: 12px; transition: border-color .18s, box-shadow .18s, background .18s; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #8aa4d6; box-shadow: var(--ring); }
.search-box { height: 44px; }
.search-box:focus-within { border-color: #8aa4d6; box-shadow: var(--ring); }
.select-compact { height: 44px; }

/* ---------- cards ---------- */
.metric, .gauge, .activity-panel, .expiry-panel, .backup-picker, .backup-list, .database-import, .edit-form, .health-box, .extend-form, .spotlight {
    border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
}
.metric { background: linear-gradient(160deg, var(--surface-2), var(--surface) 62%); min-height: 124px; transition: transform .22s var(--ease), border-color .22s; }
.metric:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.metric::after { content: ""; position: absolute; inset: auto -30% -60% auto; width: 140px; height: 140px; border-radius: 50%; background: radial-gradient(circle, rgba(120, 169, 255, .12), transparent 70%); pointer-events: none; }
.metric strong { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.metric > .icon { box-sizing: content-box; padding: 9px; background: var(--surface-3); border-radius: 12px; color: var(--soft); left: 14px; top: 14px; }
.gauge { background: linear-gradient(160deg, var(--surface-2), var(--surface) 70%); }
.gauge > i { height: 7px; border-radius: 999px; }
.gauge > i b { border-radius: 999px; }
.section-head h2 { font-size: 16px; font-weight: 800; }
.agent-alert { border-radius: 16px; }

/* ---------- tables ---------- */
.bot-table-wrap { border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.data-table th { height: 46px; font-weight: 600; letter-spacing: .02em; }
.data-table td { height: 68px; }
.data-table tbody tr { transition: background .15s; }
.customer-cell > span { width: 38px; height: 38px; background: linear-gradient(135deg, var(--surface-3), var(--surface-2)); }
.status { border-radius: 999px; padding: 5px 11px; font-weight: 600; }
.status i { box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.chip { border-radius: 999px; }

/* ---------- dialogs ---------- */
.modal-backdrop, .drawer-backdrop { background: rgba(0, 0, 0, .66); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fadeIn .2s ease-out; }
html[data-theme="light"] .modal-backdrop, html[data-theme="light"] .drawer-backdrop { background: rgba(20, 24, 28, .42); }
.modal-panel { border-radius: 22px; box-shadow: var(--shadow-2); animation: popIn .25s var(--ease); }
.drawer-panel { box-shadow: var(--shadow-2); animation: slideIn .3s var(--ease); }
.drawer-panel > header, .modal-panel > header { position: sticky; top: 0; z-index: 3; background: inherit; backdrop-filter: blur(10px); }
.action-grid button { border-radius: 14px; transition: background .18s, border-color .18s, transform .18s var(--ease); }
.action-grid button:hover { transform: translateY(-2px); }
.danger-action { border-radius: 14px; }
.toast { border-radius: 14px; backdrop-filter: blur(8px); box-shadow: var(--shadow-2); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes slideIn { from { transform: translateX(-26px); opacity: 0; } }

/* ---------- login ---------- */
.login-page { background:
    radial-gradient(700px 380px at 50% -10%, rgba(120, 169, 255, .12), transparent 65%),
    radial-gradient(500px 300px at 85% 100%, rgba(255, 255, 255, .04), transparent 70%), #080808; }
html[data-theme="light"] .login-page { background: radial-gradient(700px 380px at 50% -10%, rgba(47, 111, 209, .12), transparent 65%), var(--bg); }
.login-shell { width: min(430px, 100%); }
.login-brand { margin-bottom: 26px; }
.login-panel { border-radius: 24px; padding: 32px; box-shadow: var(--shadow-2); background: linear-gradient(180deg, var(--surface-2), var(--surface) 55%); }
.login-heading h1 { font-size: 24px; font-weight: 800; }
.secure-badge { border-radius: 999px; padding: 6px 12px; }

/* ---------- customer portal ---------- */
.portal-shell { --panel: var(--surface); }
.portal-head { min-height: 74px; }
.portal-intro h1 { font-weight: 800; }
.portal-bot { border-radius: var(--radius-lg); background: linear-gradient(160deg, var(--surface-2), var(--surface) 65%); box-shadow: var(--shadow-1); transition: transform .22s var(--ease), border-color .22s; }
.portal-bot:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.portal-bot dl { border-radius: 14px; overflow: hidden; }
.status-pill { border-radius: 999px; padding: 5px 12px; font-weight: 600; }
.portal-list button { border-radius: 14px; padding: 14px 12px; transition: background .15s; }
.portal-list button:hover { background: var(--surface-2); }
.portal-section .payment-table { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-1); }

/* ---------- tablets ---------- */
@media (max-width: 1050px) {
    .topbar { height: 78px; }
    .metric strong { font-size: 26px; }
}

/* ---------- phones ---------- */
.side-backdrop { position: fixed; inset: 0; z-index: 28; display: none; background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.side-backdrop.is-on { display: block; animation: fadeIn .2s ease-out; }

@media (max-width: 900px) {
    /* the menu becomes a drawer (app.css does this only up to 760px) */
    .sidebar { transform: translateX(105%); box-shadow: -20px 0 50px rgba(0, 0, 0, .6); }
    .sidebar.is-open { transform: none; }
    .main-content { margin-right: 0; }
    .mobile-menu { display: inline-grid !important; }
    .page-title p { display: none; }
    .top-actions .btn { font-size: 0; width: 44px; padding: 0; }
    .top-actions .btn .icon { width: 18px; height: 18px; }
}
.toolbar { flex-wrap: wrap; }

@media (max-width: 900px) {
    :root { --radius-lg: 18px; }
    body { font-size: 15px; }
    .sidebar { width: min(300px, 86vw); padding-top: calc(22px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); border-radius: 22px 0 0 22px; z-index: 40; }
    .nav-item { min-height: 50px; font-size: 15px; }
    .main-content { padding: 0 14px calc(40px + env(safe-area-inset-bottom)); margin-right: 0; }
    .topbar { height: 68px; margin: 0 -14px 16px; padding: 0 14px; gap: 10px; }
    .page-title h1 { font-size: 18px; }
    .icon-btn { width: 44px; height: 44px; }
    .top-actions .btn { width: 44px; height: 44px; min-height: 44px; border-radius: 12px; }

    /* metrics + gauges as compact tiles */
    .metrics-grid, .host-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .metric { min-height: 108px; padding: 14px; border-radius: 18px; }
    .metric strong { font-size: 24px; margin-top: 8px; }
    .metric > span { font-size: 12px; padding-inline-end: 44px; }
    .metric small { font-size: 11px; margin-top: 4px; }
    .gauge > span, .gauge > small { font-size: 11px; }
    .metric > .icon { left: 10px; top: 10px; padding: 7px; }
    .gauge { padding: 13px; border-radius: 18px; }
    .section-head { flex-wrap: wrap; margin-top: 22px; }
    .section-head .health-actions { width: 100%; }
    .health-actions { flex-wrap: wrap; }
    .health-actions .btn { flex: 1 1 auto; }

    /* toolbars */
    .toolbar { gap: 8px; }
    .search-box { width: 100%; flex: 1 1 100%; }
    .select-compact { flex: 1 1 calc(50% - 4px); min-width: 0; }
    .toolbar .btn { flex: 1 1 auto; }
    .toolbar .btn-primary { margin: 0; }

    /* every table turns into a list of cards (labels are filled in by modern.js) */
    .bot-table-wrap { border: 0; border-radius: 0; background: transparent; box-shadow: none; overflow: visible; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; min-width: 0 !important; }
    .data-table thead { display: none; }
    .data-table tr[hidden], .data-table tr[hidden] * { display: none !important; }
    .data-table tr { margin: 0 0 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(160deg, var(--surface-2), var(--surface) 70%); box-shadow: var(--shadow-1); }
    .data-table tbody tr:hover { background: linear-gradient(160deg, var(--surface-2), var(--surface) 70%); }
    .data-table td { height: auto; min-height: 40px; padding: 8px 0; border: 0; display: flex; align-items: center; justify-content: space-between; gap: 14px; text-align: left; }
    .data-table td + td { border-top: 1px dashed color-mix(in srgb, var(--line) 80%, transparent); }
    .data-table td::before { content: attr(data-label); flex: 0 0 auto; color: var(--muted); font-size: 11px; text-align: right; }
    .data-table td[data-label=""]::before { display: none; }
    .data-table tr { position: relative; }
    .data-table td:first-child { padding-top: 2px; }
    .data-table td:has(> input[type="checkbox"]) { position: absolute; top: 12px; inset-inline-end: 14px; width: auto; min-height: 0; padding: 0; border: 0; }
    .data-table td:has(> input[type="checkbox"])::before { display: none; }
    .data-table td:has(> input[type="checkbox"]) + td { border-top: 0; padding-inline-end: 34px; }
    .data-table td:last-child > .icon-btn { width: 100%; }
    .data-table td[colspan] { display: block; text-align: center; }
    .data-table td[colspan]::before { display: none; }
    .data-table .empty-state { min-height: 120px; }
    .customer-cell { min-width: 0; }
    .mono-stack, .expiry { text-align: left; }
    .data-table td .btn, .data-table td .icon-btn { margin-inline-start: auto; }
    .chip-row { justify-content: flex-end; }

    /* customers spotlight */
    .spotlight { padding: 14px; }
    .spotlight-head { flex-direction: column; align-items: stretch; }
    .spotlight-head .btn { width: 100%; }
    .spotlight-bot { grid-template-columns: 1fr auto; row-gap: 8px; }
    .spotlight-bot .btn { grid-column: 1 / -1; width: 100%; }

    /* panels */
    .dashboard-split { gap: 12px; }
    .activity-panel, .expiry-panel { padding: 14px; }
    .operation-list article { padding: 12px 0; }
    .backup-picker, .database-import { padding: 14px; }
    .backup-picker .btn { width: 100%; }
    .settings-layout { gap: 18px; }
    .settings-form, .settings-form .btn, .edit-form .btn { max-width: none; }
    .settings-form .btn { width: 100%; }
    .edit-form { margin: 14px 14px 4px; padding: 14px; }
    .health-box, .quick-extend, .extend-form { margin-inline: 14px; }
    .action-grid { grid-template-columns: repeat(2, 1fr); padding: 14px; }
    .action-grid button:last-child:nth-child(odd) { grid-column: 1 / -1; }

    /* inputs: 16px stops iOS from zooming the page on focus; 46px is a comfortable touch height */
    .field input, .field select, .field textarea, .search-box input, .select-compact { font-size: 16px; }
    .field input, .field select { min-height: 46px; }
    .search-box, .select-compact { height: 46px; }
    .btn { min-height: 46px; }
    .quick-extend button { min-height: 38px; }

    /* dialogs: bottom sheets, drawers full width */
    .modal-panel { width: calc(100% - 16px); max-height: calc(100dvh - 24px); margin: 12px auto; border-radius: 22px; }
    .drawer-panel { width: 100%; border-left: 0; }
    .drawer-panel > header, .modal-panel > header { min-height: 68px; padding: 12px 16px; }
    .modal-panel form > footer { position: sticky; bottom: 0; background: var(--surface); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
    .toast-stack { left: 12px; right: 12px; width: auto; bottom: calc(12px + env(safe-area-inset-bottom)); }
    .login-page { padding: 18px; }
    .login-panel { padding: 24px 20px; border-radius: 22px; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .database-credentials dl > div { grid-template-columns: 1fr; gap: 4px; }

    /* customer portal */
    .portal-head { padding: 10px 14px; }
    .portal-user { gap: 8px; }
    .portal-intro .btn { width: 100%; }
    .portal-bot { padding: 16px; }
    .portal-bot footer .btn { flex: 1 1 100%; }
    .portal-list button { padding: 14px 8px; }
    .portal-section .payment-table { border: 0; background: transparent; box-shadow: none; overflow: visible; }
    .payment-table .data-table { min-width: 0 !important; }
}

/* tablets: the cards sit in two columns */
@media (min-width: 620px) and (max-width: 900px) {
    .data-table tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .data-table tr { margin: 0; }
    .data-table tr:has(td[colspan]) { grid-column: 1 / -1; }
    .metrics-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .host-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
    .metrics-grid, .host-stats { grid-template-columns: 1fr 1fr; }
    .metric small { display: none; }
    .page-title h1 { font-size: 16px; }
    .action-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- offline crypto renewals ---------- */
.offline-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); margin-top: 16px; }
.offline-list > .empty-state { grid-column: 1 / -1; }
.offline-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.offline-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.offline-card > header small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.offline-card dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--line); }
.offline-card dl > div { padding: 10px 12px; background: var(--surface); min-width: 0; }
.offline-card dl > .wide { grid-column: 1 / -1; }
.offline-card dt { color: var(--muted); font-size: 10px; }
.offline-card dd { margin: 5px 0 0; font-weight: 600; font-size: 12px; overflow-wrap: anywhere; word-break: break-all; }
.offline-card dd a { color: inherit; text-decoration: underline; font-weight: 500; }
.offline-note { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.offline-note b { color: var(--text); font-weight: 600; }
.offline-receipt { display: block; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.offline-receipt img { display: block; width: 100%; max-height: 220px; object-fit: contain; }
.offline-card > footer { display: flex; flex-wrap: wrap; gap: 8px; }
.offline-card > footer .btn { flex: 1 1 140px; }
.coin-box { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 12px; min-width: 0; }
.coin-box legend { padding: 0 8px; font-weight: 700; font-size: 13px; }
.coin-price { color: var(--muted); font-size: 11px; }
.coin-price.is-bad { color: #ff7f7f; }
.offline-modal { width: min(560px, calc(100vw - 24px)); }
.offline-body { padding: 18px 20px 22px; display: grid; gap: 14px; max-height: calc(100vh - 150px); overflow-y: auto; }
.offline-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.9; }
.offline-banner { margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 12px; line-height: 1.9; }
.offline-banner.is-good { border-color: #286b3d; color: #55c878; }
.offline-banner.is-bad { border-color: #7e3131; color: #ff7f7f; }
.offline-coins { display: grid; gap: 10px; }
.offline-coin { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-align: right; cursor: pointer; transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease); }
.offline-coin:hover:not(:disabled) { border-color: var(--text); background: var(--surface-2); transform: translateY(-1px); }
.offline-coin:disabled { opacity: .5; cursor: not-allowed; }
.offline-coin small { grid-column: 1; color: var(--muted); }
.offline-coin span { grid-column: 2; grid-row: 1 / span 2; font-weight: 700; }
.offline-info { display: grid; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.offline-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); min-width: 0; }
.offline-row:last-child { border-bottom: 0; }
.offline-row > span { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.offline-row > strong { flex: 1 1 auto; min-width: 0; font-size: 12px; overflow-wrap: anywhere; word-break: break-all; text-align: left; }
.offline-row .btn { flex: 0 0 auto; padding: 5px 12px; font-size: 11px; }
.offline-proof { padding: 0; }
@media (max-width: 560px) {
    .offline-card dl { grid-template-columns: 1fr; }
    .offline-row { flex-wrap: wrap; }
    .offline-row > strong { flex-basis: 100%; order: 3; }
    .offline-body { padding: 16px 14px 20px; }
}
