/* ── Shared Barly Styles ── */

/* Design tokens. Lifting the palette into :root means a single override block
   (see Phase 5 theming) can re-skin the whole app to match the bar's AI_Theme.
   The defaults below are the original BarlyOwner colours. */
:root {
    --bg: #0A0F1E;            /* page background */
    --surface: #0F1629;       /* cards, inputs, buttons, header chrome */
    --surface-active: #131D35;/* pressed surface */
    --border: #1E2D4A;        /* borders + muted fills */
    --border-active: #2A3D5A; /* pressed secondary */
    --text: #ffffff;
    --text-muted: #94A3B8;
    --text-dim: #64748B;
    --accent: #E5A100;        /* gold primary */
    --accent-active: #D4900A;
    --accent-contrast: #ffffff;/* text/icon on top of --accent */
    --success: #22C55E;
    --danger: #EF4444;
    --danger-text: #FF6467;
    --info: #3B82F6;
    --purple: #7C3AED;
    --cyan: #06B6D4;
    --orange: #F97316;

    /* Layout */
    --content-max: 1200px;    /* centred content column cap on wide screens */
    --nav-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
a { text-decoration: none; color: inherit; }

/* Layout */
.page { display: flex; flex-direction: column; min-height: 100vh; padding: 16px; padding-top: env(safe-area-inset-top, 16px); }
.page-center { align-items: center; justify-content: center; }
.page-scroll { overflow-y: auto; }

/* Header */
.header { display: flex; align-items: center; padding: 8px 0 12px; }
.header-back { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-right: 12px; cursor: pointer; }
.header-title { font-size: 20px; font-weight: 700; flex: 1; }
.header-subtitle { font-size: 13px; color: var(--text-muted); }
.header-action { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }

/* Cards */
.card {
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
}
.card + .card { margin-top: 12px; }

/* Action cards (home page) */
.action-card {
    display: flex;
    align-items: center;
    padding: 18px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.action-card:active { background: var(--surface-active); border-color: var(--accent); }
.action-card + .action-card { margin-top: 10px; }
.action-icon {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 22px;
    flex-shrink: 0;
}
.action-info { margin-left: 14px; flex: 1; }
.action-title { font-size: 16px; font-weight: 600; }
.action-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.action-arrow { color: var(--text-dim); font-size: 18px; }

/* Sectioned home: 2-column tile grid (vertical layout, fits more in less scroll) */
.home-section + .home-section { margin-top: 18px; }
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.action-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    min-height: 116px;
    transition: border-color 0.2s, background 0.2s;
}
.action-tile:active { background: var(--surface-active); border-color: var(--accent); }
.action-tile-icon {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 22px;
    margin-bottom: 10px;
}
.action-tile-title { font-size: 14px; font-weight: 600; line-height: 1.25; }
.action-tile-desc { font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.3; }

/* Buttons */
.btn {
    display: block; width: 100%; padding: 14px;
    /* Transparent 1px border keeps every variant the same total height,
       even when btn-danger / btn-success add a coloured border. */
    border: 1px solid transparent; border-radius: 12px;
    font-size: 16px; font-weight: 700;
    cursor: pointer; text-align: center;
}
.btn + .btn { margin-top: 10px; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:active { background: var(--accent-active); }
.btn-secondary { background: var(--border); color: var(--text-muted); }
.btn-secondary:active { background: var(--border-active); }

/* Horizontal action-button row inside forms (Save / Cancel pairs).
   Cancels the default ".btn + .btn { margin-top: 10px }" so siblings
   share the same baseline, and gives both buttons equal width. */
.form-actions { display: flex; gap: 10px; align-items: stretch; margin-top: 24px; }
.form-actions .btn + .btn { margin-top: 0; }
.form-actions .btn { flex: 1; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger-text); border: 1px solid rgba(255,100,103,0.3); }
.btn-success { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }

/* Lists */
.list-item {
    display: flex; align-items: center;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.list-item + .list-item { margin-top: 8px; }
.list-item-img {
    width: 50px; height: 50px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--border);
    flex-shrink: 0;
}
.list-item-info { margin-left: 12px; flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.list-item-badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Section headers */
.section-header { display: flex; align-items: center; padding: 12px 0 8px; }
.section-header-icon { margin-right: 8px; font-size: 18px; }
.section-header-title { font-size: 16px; font-weight: 700; }
.section-header-subtitle { font-size: 12px; color: var(--text-dim); margin-left: auto; }

/* Toggle switch */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border); border-radius: 12px; transition: background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--success); }
.toggle-knob {
    position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
    background: white; border-radius: 50%; transition: transform 0.2s;
}
.toggle input:checked ~ .toggle-knob { transform: translateX(20px); }

/* Colors */
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--accent); }
.text-green { color: var(--success); }
.text-red { color: var(--danger-text); }
.text-blue { color: var(--info); }
.text-purple { color: var(--purple); }
.bg-gold { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.bg-green { background: rgba(34,197,94,0.15); }
.bg-blue { background: rgba(59,130,246,0.15); }
.bg-purple { background: rgba(124,58,237,0.15); }
.bg-red { background: rgba(239,68,68,0.15); }
.bg-cyan { background: rgba(6,182,212,0.18); }
.bg-orange { background: rgba(249,115,22,0.18); }

/* Spinner */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Status bar */
.status-bar { position: fixed; top: 0; left: 0; right: 0; padding: 10px 16px; text-align: center; font-size: 14px; font-weight: 600; z-index: 100; transition: transform 0.3s; transform: translateY(-100%); }
.status-bar.show { transform: translateY(0); }
.status-bar.success { background: var(--success); color: white; }
.status-bar.error { background: var(--danger); color: white; }

/* Utility */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* ============================================================================
   Top navigation bar — phone: hidden (the home hub + back button drive nav).
   Tablet/desktop: a horizontal bar above the page. Lives in _Layout.cshtml.
   ========================================================================== */
/* Scrollbars — hide HORIZONTAL scrollbars app-wide (scrolling still works);
   vertical scrollbars are left intact. WebKit/Blink can target the horizontal
   bar directly; the .no-scrollbar utility hides a container's bar entirely and
   is applied to the horizontal-only chip rows / nav so Firefox hides them too. */
::-webkit-scrollbar:horizontal { height: 0; display: none; }
.no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

.appbar, .topnav { display: none; }

/* Opt-in helper: add .cards-grid to a list container to flow its children into
   multiple columns on wide screens (used by the list-heavy pages). It is a
   no-op on phones — children keep their own stacking/margins there. */

/* ============================================================================
   Responsive — phones keep the original single-column layout untouched.
   ========================================================================== */
@media (min-width: 768px) {
    /* Centre the page content in a capped column so text/line-lengths stay
       comfortable on wide screens instead of stretching edge to edge. */
    .page {
        max-width: var(--content-max);
        margin-inline: auto;
        width: 100%;
        padding: 24px 28px;
    }
    /* Centred-form / single-control pages: cap narrower so forms and controls
       don't stretch to an awkward line length on wide screens. */
    .page.page-narrow { max-width: 640px; }

    /* Sticky app bar = a brand strip (Barly logo) above the nav tabs. The top
       padding clears the device status bar / embedding chrome (safe-area inset,
       with an 8px floor) so the nav isn't trapped under it on iPad standalone /
       embedded webviews. Background + border live here; the nav sits inside. */
    .appbar {
        display: block;
        position: sticky;
        top: 0;
        z-index: 60;
        background: color-mix(in srgb, var(--surface, #0F1629) 88%, transparent);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border, #1E2D4A);
        padding-top: max(8px, env(safe-area-inset-top, 0px));
    }
    .appbar-logo { display: flex; align-items: center; padding: 10px 24px 6px; }
    .appbar-logo img { height: 34px; width: auto; display: block; }

    /* Top nav — clean, modern tab bar: text-only links with an accent underline
       indicator for the active page. All theme-driven. */
    .topnav {
        display: flex;
        align-items: stretch;
        height: var(--nav-h);
        padding: 0 24px;
        overflow-x: auto;
        scrollbar-width: none; /* Firefox — hide the nav's scrollbar */
    }
    .topnav::-webkit-scrollbar { display: none; }
    .topnav-links { display: flex; align-items: stretch; gap: 0; }
    .topnav-links a {
        display: inline-flex; align-items: center;
        padding: 0 14px;
        font-size: 14px; font-weight: 500; color: var(--text-muted);
        white-space: nowrap;
        border-bottom: 2px solid transparent;
        transition: color 0.15s, border-color 0.15s;
    }
    .topnav-links a:hover { color: var(--text); }
    .topnav-links a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

    /* Home hub tiles flow to fill the wider column instead of locking to 2. */
    .action-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

    /* List-heavy pages opt into a multi-column card grid. */
    .cards-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 10px;
    }
    .cards-grid > * + * { margin-top: 0; }

    /* Form button rows shouldn't stretch the full wide column. */
    .form-actions { max-width: 520px; }
}

@media (min-width: 1200px) {
    .page { padding: 28px 32px; }
    .action-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
