/* ==========================================================
   TRESTLE GLOBAL STYLES
   Version: 2.0 — Premium refresh
========================================================== */

/* ==========================================================
   GOOGLE FONT
========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ==========================================================
   ROOT VARIABLES
========================================================== */

:root {

    /* Brand */

    --brand-cyan: #00B7FB;
    --brand-blue: #1765F5;
    --brand-violet: #7138F5;
    --brand-purple: #B43CFF;

    --gradient: linear-gradient(110deg, #00B7FB 0%, #1765F5 48%, #7138F5 78%, #B43CFF 100%);

    /* Primary (brand blue; gradient is used for primary buttons and active nav) */

    --primary: #1765F5;
    --primary-dark: #1250C8;
    --primary-light: #EAF1FE;

    /* Secondary (legacy names mapped onto brand colours) */

    --navy: #0B0D14;
    --sky: #00B7FB;

    --purple: #7138F5;
    --blue: #1765F5;
    --yellow: #F59E0B;

    --teal: #06B6D4;
    --mint: #22C55E;
    --coral: #EF4444;

    /* Status */

    --success: #22C55E;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #06B6D4;
    --in-progress: #3B82F6;
    --pending: #F59E0B;
    --archived: #94A3B8;

    /* Semantic tokens (light values; dark block below redefines the same names) */

    --bg: #F2F4F8;
    --surface: #FFFFFF;
    --surface-raised: #FFFFFF;
    --surface-hover: #F7F8FB;
    --hairline: rgba(11, 13, 20, .08);

    --text-1: #0B0D14;
    --text-2: #4B5565;
    --text-3: #6B7280;

    --shadow-card:
        0 1px 2px rgba(11, 13, 20, .04),
        0 6px 16px rgba(11, 13, 20, .05);

    --shadow-raised:
        0 2px 4px rgba(11, 13, 20, .05),
        0 12px 28px rgba(11, 13, 20, .08);

    --sidebar-bg: rgba(255, 255, 255, .72);
    --control-track: #E9ECF2;
    --focus-ring: rgba(23, 101, 245, .5);
    --tone-violet: #7138F5;

    /* Legacy names mapped onto the semantic tokens */

    --background: var(--bg);

    --text: var(--text-1);
    --text-light: var(--text-2);
    --text-secondary: var(--text-2);
    --text-faint: var(--text-3);

    --border: var(--hairline);
    --border-soft: var(--surface-hover);

    --shadow-xs: var(--shadow-card);
    --shadow: var(--shadow-card);
    --shadow-md: var(--shadow-raised);

    /* Effects */

    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;

    --transition: .18s ease;

}

/* ==========================================================
   DARK THEME
   Toggled site-wide via the "Dark Mode" switch in the sidebar
   (every page — see .sidebar-user in each page's <body>), applied
   as `data-theme="dark"` on <html> by js/shared/app.js
   (initializeTheme()), persisted in localStorage. Redefining the
   same custom properties here means every component that already
   uses var(--surface)/var(--text)/var(--border)/etc. (which is
   most of the app) re-themes automatically with no extra CSS.
   Components that hardcode a literal color instead of a variable
   (a handful of `background: white`/`#F7F8FA` spots, mostly in
   layout.css's sidebar) won't respond to this and were fixed
   individually where they'd otherwise look broken in dark mode —
   see layout.css. Some page-specific components elsewhere in the
   app may still have their own hardcoded literals not yet audited
   for dark mode; this pass covers the sidebar and Dashboard fully.
========================================================== */

[data-theme="dark"] {

    --primary: #4D8DFF;
    --primary-dark: #3B7BF0;
    --primary-light: rgba(77, 141, 255, .16);

    --bg: #0B0D14;
    --surface: #141722;
    --surface-raised: #1C2030;
    --surface-hover: #1A1E2B;
    --hairline: rgba(255, 255, 255, .08);

    --text-1: rgba(255, 255, 255, .92);
    --text-2: rgba(255, 255, 255, .62);
    --text-3: rgba(255, 255, 255, .42);

    --shadow-card:
        inset 0 1px 0 rgba(255, 255, 255, .04),
        0 1px 2px rgba(0, 0, 0, .4);

    --shadow-raised:
        inset 0 1px 0 rgba(255, 255, 255, .06),
        0 12px 32px rgba(0, 0, 0, .55);

    --sidebar-bg: rgba(20, 23, 34, .72);
    --control-track: #0F121B;
    --focus-ring: rgba(77, 141, 255, .6);
    --tone-violet: #A78BFA;

    /* Legacy aliases must be re-declared here: var() inside :root resolves
       there and the resolved light value is inherited, so redefining only
       the semantic tokens in this block would leave them stuck on light. */

    --background: var(--bg);

    --text: var(--text-1);
    --text-light: var(--text-2);
    --text-secondary: var(--text-2);
    --text-faint: var(--text-3);

    --border: var(--hairline);
    --border-soft: var(--surface-hover);

    --shadow-xs: var(--shadow-card);
    --shadow: var(--shadow-card);
    --shadow-md: var(--shadow-raised);

}

/* ==========================================================
   RESET
========================================================== */

*,
*::before,
*::after {

    margin: 0;
    padding: 0;

    box-sizing: border-box;

}

html {

    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;

}

body {

    font-family: "Inter", sans-serif;

    background: var(--background);

    color: var(--text);

    font-size: 14px;

    line-height: 1.5;

    min-height: 100vh;

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;

}

/* Session guard (js/shared/auth.js): app pages start as
   <html class="auth-pending"> and stay hidden — including modals
   appended to body — until the session check passes. The body's
   background still paints, so there's no flash of the wrong theme. */
html.auth-pending body {

    visibility: hidden;

}

/* Shown by the guard when the session can't be checked; visible
   even inside the hidden body. */
.auth-gate-message {

    visibility: visible;

    position: fixed;
    inset: 0;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;

    padding: 16px;

    text-align: center;

    background: var(--background);

}

.auth-gate-message h2 {

    font-size: 20px;

}

.auth-gate-message p {

    max-width: 420px;

    color: var(--text-secondary);

}

img {

    display: block;

    max-width: 100%;

}

button,
input,
select,
textarea {

    font: inherit;

}

button {

    cursor: pointer;

}

a {

    text-decoration: none;

    color: inherit;

}

ul {

    list-style: none;

}

/* ==========================================================
   FOCUS
   Keyboard focus only (focus-visible); mouse clicks leave no ring.
========================================================== */

:focus:not(:focus-visible) {

    outline: none;

}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {

    outline: 2px solid var(--focus-ring);

    outline-offset: 2px;

}

/* ==========================================================
   TYPOGRAPHY
========================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {

    font-family: "Inter", sans-serif;

    color: var(--text);

    font-weight: 600;

    line-height: 1.25;

    letter-spacing: -.01em;

}

h1 {

    font-size: 24px;

}

h2 {

    font-size: 20px;

}

h3 {

    font-size: 17px;

}

h4 {

    font-size: 15px;

}

h5 {

    font-size: 14px;

}

h6 {

    font-size: 13px;

}

p {

    color: var(--text-light);

    font-size: 14px;

}

small {

    font-size: 12.5px;

}

/* ==========================================================
   APP LAYOUT
========================================================== */

.app {

    display: flex;

    min-height: 100vh;

}

.main-content {

    flex: 1;

    padding: 28px 32px;

    overflow-x: auto;

}

/* ==========================================================
   PAGE HEADER
========================================================== */

.page-header {

    display: flex;

    justify-content: space-between;

    align-items: center;

    gap: 24px;

    margin-bottom: 24px;

}

.header-actions {

    display: flex;

    align-items: center;

    gap: 10px;

    flex-wrap: wrap;

}

/* ==========================================================
   CONTAINERS
========================================================== */

.container {

    max-width: 1600px;

    margin: auto;

}

.section {

    margin-bottom: 32px;

}

/* ==========================================================
   UTILITIES
========================================================== */

.flex {

    display: flex;

}

.flex-column {

    display: flex;

    flex-direction: column;

}

.align-center {

    align-items: center;

}

.justify-between {

    justify-content: space-between;

}

.justify-center {

    justify-content: center;

}

.text-center {

    text-align: center;

}

.full-width {

    width: 100%;

}

.hidden {

    display: none !important;

}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

/* ==========================================================
   SCROLLBAR
========================================================== */

::-webkit-scrollbar {

    width: 8px;

    height: 8px;

}

::-webkit-scrollbar-track {

    background: transparent;

}

::-webkit-scrollbar-thumb {

    background: var(--border);

    border-radius: 999px;

}

::-webkit-scrollbar-thumb:hover {

    background: var(--primary);

}

/* ==========================================================
   SELECTION
========================================================== */

::selection {

    background: var(--primary);

    color: white;

}

/* ==========================================================
   HORIZONTAL RULE
========================================================== */

hr {

    border: none;

    border-top: 1px solid var(--border);

    margin: 24px 0;

}

/* ==========================================================
   ANIMATIONS
========================================================== */

.fade-in {

    animation: fadeIn .3s ease;

}

@keyframes fadeIn {

    from {

        opacity: 0;
        transform: translateY(8px);

    }

    to {

        opacity: 1;
        transform: translateY(0);

    }

}

.scale-in {

    animation: scaleIn .2s ease;

}

@keyframes scaleIn {

    from {

        opacity: 0;
        transform: scale(.97);

    }

    to {

        opacity: 1;
        transform: scale(1);

    }

}

/* ==========================================================
   RESPONSIVE
========================================================== */

@media (max-width: 1024px) {

    .main-content {

        padding: 22px;

    }

}

@media (max-width: 768px) {

    .page-header {

        flex-direction: column;

        align-items: flex-start;

    }

    h1 {

        font-size: 21px;

    }

    h2 {

        font-size: 18px;

    }

}

@media (max-width: 480px) {

    .main-content {

        padding: 16px;

    }

}