/* ==========================================================================
   TROVA Dashboard — app.css
   Dark-first, Linear/Vercel aesthetic. Brand tokens at the top; everything
   else reads from them. Accent color is overridden per-tenant via inline
   <style>:root{--accent:...}</style> in layout.php.
   ========================================================================== */

/* ── Tokens ───────────────────────────────────────────────────────────── */
:root {
    --bg:             #0a0a0a;
    --bg-alt:         #080808;
    --card:           #111111;
    --card-hover:     #161616;
    --border:         rgba(255,255,255,0.06);
    --border-strong:  rgba(255,255,255,0.12);
    --orange:         #ff6b00;
    --orange-hover:   #ff8533;
    --green:          #16a34a;
    --blue:           #5b9cff;
    --red:            #ef4444;
    --amber:          #f59e0b;
    --text:           #f0f0f0;
    --text-dim:       #c0c0c0;
    --muted:          #888888;
    --muted-dim:      #555555;
    --accent:         var(--orange);  /* overridden per-tenant */

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow:    0 4px 14px rgba(0,0,0,0.5);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.55);

    --sidebar-width: 244px;
    --sidebar-collapsed-width: 64px;
    --header-height: 64px;
}

/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; color-scheme: dark; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[x-cloak] { display: none !important; }

/* ── Layout: auth mode ────────────────────────────────────────────────── */
.auth-main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(ellipse at top, rgba(255,107,0,0.08), transparent 60%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 32px;
}
.logo-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 900;
    letter-spacing: -0.5px;
    font-size: 13px;
}
.logo-word { font-weight: 800; letter-spacing: -0.5px; font-size: 18px; }
.auth-title { font-size: 24px; font-weight: 800; letter-spacing: -0.3px; margin-bottom: 6px; }
.auth-sub { color: var(--muted); margin-bottom: 28px; font-size: 14px; }
.auth-links {
    margin-top: 18px;
    text-align: center;
    font-size: 14px;
}
.auth-links a { color: var(--muted); }
.auth-links a:hover { color: var(--text); }
.auth-footer {
    margin-top: 32px;
    display: flex;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}
.auth-footer a:hover { color: var(--text); }

/* ── Layout: app mode ─────────────────────────────────────────────────── */
body.mode-app { display: flex; min-height: 100vh; }
.app-sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-alt);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    transition: width 0.18s ease;
}
.app-sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.app-sidebar.collapsed .sidebar-label,
.app-sidebar.collapsed .sidebar-company,
.app-sidebar.collapsed .sidebar-lock,
.app-sidebar.collapsed .sidebar-foot { display: none; }

.sidebar-head {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.sidebar-logomark {
    display: grid;
    place-items: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 900;
    font-size: 12px;
    flex-shrink: 0;
}
.sidebar-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.sidebar-company {
    font-weight: 700;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    width: 28px; height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: grid;
    place-items: center;
}
.sidebar-toggle:hover { color: var(--text); border-color: var(--border-strong); }

.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    position: relative;
}
.sidebar-link:hover { background: var(--card-hover); color: var(--text); }
.sidebar-link.is-active {
    background: rgba(255,107,0,0.08);
    color: var(--text);
    box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar-link.is-locked { color: var(--muted-dim); }
.sidebar-link.is-locked:hover { color: var(--text-dim); }
.sidebar-icon {
    width: 16px; height: 16px;
    flex-shrink: 0;
    display: inline-block;
    opacity: 0.8;
}
.sidebar-lock {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-foot {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tier-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.tier-starter { background: rgba(91,156,255,0.12); color: var(--blue); }
.tier-growth  { background: rgba(255,107,0,0.12); color: var(--orange); }
.tier-scale   { background: rgba(22,163,74,0.12); color: var(--green); }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.app-header {
    height: var(--header-height);
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 20;
}
.app-header-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.2px;
}
.app-header-right { position: relative; }
.user-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px 6px 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text);
    transition: border-color 0.12s, background 0.12s;
}
.user-btn:hover { border-color: var(--border-strong); background: var(--card-hover); }
.user-avatar {
    width: 28px; height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
}
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--muted); }
.user-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
}
.user-menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-dim);
    border-radius: 6px;
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
}
.user-menu-item:hover { background: var(--card-hover); color: var(--text); }
.user-menu-btn { padding: 8px 12px; }
.user-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

.app-content {
    flex: 1;
    padding: 32px;
    max-width: 1400px;
    width: 100%;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="url"],
input[type="search"], input[type="date"], input[type="time"],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.12s, background 0.12s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    background: var(--card);
}
input:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s;
    border: 1px solid transparent;
    line-height: 1;
}
.btn-primary:active, .btn-secondary:active, .btn-ghost:active, .btn-danger:active { transform: translateY(1px); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--orange-hover); border-color: var(--orange-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
    background: var(--card);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--card-hover); }
.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}
.btn-block { width: 100%; }

/* ── Flash messages ───────────────────────────────────────────────────── */
.flash-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    max-width: 420px;
}
.auth-main .flash-stack { position: static; margin-bottom: 16px; }
.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 14px;
}
.flash-success { border-color: rgba(22,163,74,0.45); color: var(--green); }
.flash-error   { border-color: rgba(239,68,68,0.45); color: var(--red); }
.flash-info    { border-color: rgba(91,156,255,0.45); color: var(--blue); }
.flash-warn    { border-color: rgba(245,158,11,0.45); color: var(--amber); }
.flash-message { flex: 1; }
.flash-close {
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    opacity: 0.6;
}
.flash-close:hover { opacity: 1; }

/* ── Banner ───────────────────────────────────────────────────────────── */
.banner {
    padding: 12px 32px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.banner-warn { background: rgba(245,158,11,0.08); color: var(--amber); }
.banner-cta { margin-left: auto; color: inherit; font-weight: 700; text-decoration: underline; }

/* ── Cards / Welcome ──────────────────────────────────────────────────── */
.welcome-panel {
    max-width: 860px;
}
.welcome-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: rgba(22,163,74,0.12);
    color: var(--green);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 16px;
}
.pulse-dot {
    width: 8px; height: 8px;
    background: var(--green);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(22,163,74,0.6);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(22,163,74,0.5); }
    70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); }
    100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}
.welcome-title {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
    margin-bottom: 12px;
}
.welcome-company { color: var(--accent); }
.welcome-tier { color: var(--accent); text-transform: capitalize; }
.welcome-sub { color: var(--muted); max-width: 620px; margin-bottom: 32px; }

.welcome-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}
.kv-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kv-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 600;
}
.kv-value {
    font-size: 18px;
    font-weight: 700;
}

.welcome-features {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}
.welcome-feat-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.feat-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.feat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.feat-row:hover { background: var(--card-hover); }
.feat-icon {
    width: 18px; height: 18px;
    display: grid; place-items: center;
    font-size: 12px;
    font-weight: 700;
    border-radius: 4px;
    flex-shrink: 0;
}
.feat-on .feat-icon  { background: rgba(22,163,74,0.15); color: var(--green); }
.feat-off .feat-icon { background: rgba(136,136,136,0.12); color: var(--muted); }
.feat-off { color: var(--muted); }
.feat-label { flex: 1; }
.feat-upgrade {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ── Error pages ──────────────────────────────────────────────────────── */
body.mode-error {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at top, rgba(239,68,68,0.06), transparent 60%),
        var(--bg);
}
.error-main {
    text-align: center;
    padding: 40px;
    max-width: 500px;
}
.error-code {
    font-size: 96px;
    font-weight: 900;
    letter-spacing: -4px;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 16px;
}
.error-upgrade { font-size: 72px; }
.error-title { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.error-sub { color: var(--muted); margin-bottom: 24px; }
.error-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.error-debug {
    margin-top: 32px;
    text-align: left;
    font-size: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}
.error-debug pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    color: var(--text-dim);
    max-height: 300px;
    overflow: auto;
}

/* ── Utilities ────────────────────────────────────────────────────────── */
.muted   { color: var(--muted); }
.mono    { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.hidden  { display: none !important; }

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .app-sidebar {
        position: fixed;
        left: 0; top: 0;
        z-index: 40;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .app-sidebar.open { transform: translateX(0); }
    .app-header { padding: 0 16px; }
    .app-content { padding: 16px; }
    .welcome-title { font-size: 24px; }
    .auth-card { padding: 24px; }
}
