/* ============================================================================
   Atlas — personal app directory.
   Design intent: a clean, glanceable dashboard. Distinct from Ledger's
   editorial / serif feel by using a more technical / utility aesthetic.
   Mono accents, slightly more compact rows, status-first hierarchy.
   ============================================================================ */

:root {
    color-scheme: light dark;

    /* Light theme */
    --bg:           #f7f7f5;
    --surface:     #ffffff;
    --surface-2:   #f0f0ec;
    --ink:         #1c1c1c;
    --ink-soft:    #555;
    --ink-muted:   #888;
    --line:        #e2e2dd;
    --accent:      #2a5fb8;
    --accent-soft: #6b8fc9;
    --positive:    #2a8a4a;
    --warning:     #c87f0a;
    --danger:      #b8402a;
    --inactive:    #999;

    /* Status badges */
    --st-active:   #2a8a4a;
    --st-inactive: #999;
    --st-archived: #777;
    --st-demo:     #2a5fb8;
    --st-dev:      #c87f0a;

    --radius:      10px;
    --radius-sm:   6px;
    --radius-lg:   16px;
    --shadow:      0 1px 2px rgba(0,0,0,0.04), 0 2px 8px rgba(0,0,0,0.04);

    --font-sys:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
    --font-mono:   ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:           #131314;
        --surface:     #1c1c1e;
        --surface-2:   #25252a;
        --ink:         #ececec;
        --ink-soft:    #b4b4b4;
        --ink-muted:   #888;
        --line:        #2a2a2e;
        --accent:      #6b9aed;
        --accent-soft: #4a72bb;
        --positive:    #5fce80;
        --warning:     #edb060;
        --danger:      #ed7a60;
        --inactive:    #777;

        --st-active:   #5fce80;
        --st-inactive: #777;
        --st-archived: #666;
        --st-demo:     #6b9aed;
        --st-dev:      #edb060;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-sys);
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ----- Boot spinner ----- */
.boot-spinner {
    display: flex; align-items: center; justify-content: center;
    min-height: 100dvh;
}
.boot-spinner span {
    width: 28px; height: 28px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Layout shell ----- */
#app[data-loading="false"] {
    min-height: 100dvh;
    padding: 0 0 60px;
}

.topbar {
    position: sticky; top: 0; z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 14px 18px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.topbar-brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 600; font-size: 17px; letter-spacing: -0.01em;
}
.topbar-brand .mark { font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-muted); }

main { max-width: 1100px; margin: 0 auto; padding: 18px; }

/* ----- Toolbar (search + filters) ----- */
.toolbar {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-bottom: 18px;
    align-items: center;
}
.search {
    flex: 1; min-width: 220px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12.5px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.chip:hover { border-color: var(--accent-soft); }
.chip.active {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.btn {
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.12s ease;
}
.btn:hover { opacity: 0.9; }
.btn.ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--surface); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.full { width: 100%; }

.icon-btn {
    padding: 6px 8px;
    background: transparent;
    border: none;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.12s ease, color 0.12s ease;
    font-size: 15px;
    line-height: 1;
}
.icon-btn:hover {
    background: var(--surface-2);
    color: var(--ink);
}

/* ----- App grid (the home page) ----- */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.app-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.12s ease, transform 0.06s ease;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
    width: 100%;
}
.app-card:hover {
    border-color: var(--accent);
}
.app-card:active { transform: scale(0.99); }

.app-card-head { display: flex; align-items: center; gap: 10px; }
.app-card-icon {
    font-size: 22px;
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.app-card-title {
    font-weight: 600;
    font-size: 15.5px;
    flex: 1;
    line-height: 1.2;
}

.app-card-desc {
    color: var(--ink-soft);
    font-size: 13px;
    line-height: 1.45;
    /* Two-line clamp */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-card-meta {
    display: flex; gap: 12px; flex-wrap: wrap;
    font-size: 12px;
    color: var(--ink-muted);
}

.app-card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--surface-2);
    border-radius: 999px;
    color: var(--ink-soft);
}

/* ----- Status badges ----- */
.status-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-badge::before {
    content: '';
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
}
.status-active   { background: color-mix(in srgb, var(--st-active) 14%, transparent);   color: var(--st-active);   }
.status-inactive { background: color-mix(in srgb, var(--st-inactive) 14%, transparent); color: var(--st-inactive); }
.status-archived { background: color-mix(in srgb, var(--st-archived) 12%, transparent); color: var(--st-archived); }
.status-demo     { background: color-mix(in srgb, var(--st-demo) 14%, transparent);     color: var(--st-demo);     }
.status-dev      { background: color-mix(in srgb, var(--st-dev) 14%, transparent);      color: var(--st-dev);      }

/* Dim inactive/archived cards in the grid */
.app-card.dim-status { opacity: 0.6; }
.app-card.dim-status:hover { opacity: 1; }

/* ----- Empty state ----- */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-muted);
}
.empty-mark {
    font-size: 40px;
    color: var(--line);
    margin-bottom: 10px;
}

/* ----- Detail view ----- */
.detail-header {
    display: flex; align-items: flex-start; gap: 14px;
    margin-bottom: 24px;
}
.detail-icon {
    font-size: 32px;
    width: 56px; height: 56px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    flex-shrink: 0;
}
.detail-title {
    flex: 1;
}
.detail-title h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.detail-title .desc {
    color: var(--ink-soft);
    font-size: 14px;
    margin-top: 4px;
}
.detail-title .meta {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-top: 8px;
    font-size: 12px;
}

.section {
    margin-bottom: 28px;
}
.section-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.section-head h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
}

.row-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.row-main { flex: 1; min-width: 0; }
.row-label {
    font-weight: 600;
    font-size: 14px;
    display: flex; align-items: center; gap: 8px;
}
.row-sub {
    font-size: 12.5px;
    color: var(--ink-muted);
    margin-top: 3px;
    font-family: var(--font-mono);
    word-break: break-all;
    line-height: 1.4;
}
.row-notes {
    font-size: 12px;
    color: var(--ink-soft);
    margin-top: 4px;
    font-style: italic;
}

.row-card.inactive {
    opacity: 0.5;
    background: var(--surface-2);
}

/* Tap-targets and action buttons */
.row-actions {
    display: flex; gap: 4px;
    align-items: center;
}

/* Login row password field */
.password-cell {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--font-mono);
    font-size: 13px;
}
.password-display {
    user-select: all;
    cursor: pointer;
    padding: 4px 8px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    transition: background 0.12s ease;
    letter-spacing: 0.5px;
    min-width: 60px;
    display: inline-block;
}
.password-display:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.password-hidden { color: var(--ink-muted); letter-spacing: 2px; }

/* ----- Sheet (modal) ----- */
.scrim {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
.sheet {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}
.sheet-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 600; }

/* Form */
.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-muted);
    margin-bottom: 6px;
}
.field input, .field select, .field textarea {
    width: 100%;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 14px;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-help { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }

/* Stack utility */
.stack > * + * { margin-top: 14px; }
.stack-sm > * + * { margin-top: 8px; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--bg);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: toastIn 0.2s ease;
}
@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.error-msg {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 14px;
}

/* Auth */
.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow);
}
.auth-card h1 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 600;
}
.auth-card .sub {
    color: var(--ink-muted);
    font-size: 14px;
    margin-bottom: 22px;
}

.muted { color: var(--ink-muted); }
.mono { font-family: var(--font-mono); }
.hide { display: none !important; }

/* ----- Tabs on app detail page ----- */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 20px;
    overflow-x: auto;
    /* hide horizontal scrollbar */
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
    cursor: pointer;
}
.tab:hover {
    color: var(--ink);
    text-decoration: none;
}
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.tab-count {
    display: inline-block;
    min-width: 18px;
    padding: 1px 6px;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-muted);
    line-height: 1.3;
    text-align: center;
}
.tab.active .tab-count {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    color: var(--accent);
}

/* ----- Document / login kind tag (small inline badge) ----- */
.doc-kind {
    display: inline-block;
    padding: 1px 7px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--surface-2);
    color: var(--ink-soft);
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: 2px;
}

/* ----- Code field block (commands rendered as code) ----- */
.code-block {
    display: inline-block;
    padding: 4px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 13px;
    word-break: break-all;
    line-height: 1.5;
}

/* ----- Document file upload elements ----- */
.source-toggle {
    display: flex;
    gap: 8px;
}
.source-opt {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
    color: var(--ink);
    margin-bottom: 0;
}
.source-opt:has(input:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.source-opt input[type=radio] {
    margin: 0;
    width: auto;
    accent-color: var(--accent);
}

.current-file {
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 8px;
}

.doc-file-info {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink-soft);
}

/* File input — use system default styling for predictability */
input[type=file] {
    width: 100%;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ----- Google sign-in button (auth screen) ----- */
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-weight: 500;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.12s ease, border-color 0.12s ease;
    margin-bottom: 0;
}
.btn-google:hover {
    background: var(--surface-2);
    border-color: var(--accent-soft);
    text-decoration: none;
}
.btn-google .google-g {
    flex-shrink: 0;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: var(--ink-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

/* ----- Topbar avatar (when signed in via Google) ----- */
.topbar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--line);
}
