/* =============================================================
   wa-platform admin
   Refined editorial design - Fraunces + IBM Plex Sans
   ============================================================= */

:root {
    /* Palette */
    --bg:            #F7F4EE;        /* warm off-white */
    --bg-raised:    #FFFCF6;
    --surface:      #FFFFFF;
    --border:       #E7E1D3;
    --border-strong:#D3CBB6;

    --ink:          #1A1A1A;
    --ink-soft:     #4A4A4A;
    --ink-muted:    #8A8578;

    --sidebar-bg:   #121211;
    --sidebar-ink:  #E8E2CF;
    --sidebar-muted:#8F8A7A;
    --sidebar-hover:#1E1E1B;
    --sidebar-active:#262621;

    --accent:       #0E7C66;         /* refined deep teal-green */
    --accent-ink:   #FFFFFF;
    --accent-soft:  #E4F0EB;
    --accent-dark:  #0A5A4A;

    --danger:       #B4412B;
    --danger-soft:  #F8E6DF;
    --warn:         #C08844;
    --warn-soft:    #F8ECD6;
    --success:      var(--accent);
    --success-soft: var(--accent-soft);

    /* Type */
    --font-display: "Fraunces", "Playfair Display", Georgia, serif;
    --font-body:    "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono:    "JetBrains Mono", "SF Mono", Consolas, monospace;

    /* Geometry */
    --radius:       6px;
    --radius-lg:    10px;
    --shadow-sm:    0 1px 2px rgba(26, 26, 26, 0.04);
    --shadow:       0 4px 20px -8px rgba(26, 26, 26, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 500;
    font-variation-settings: "SOFT" 30, "opsz" 144;
    color: var(--ink);
    letter-spacing: -0.01em;
    margin: 0;
}

h1 { font-size: 2rem; line-height: 1.15; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }

code, pre, .mono { font-family: var(--font-mono); font-size: 0.875em; }

/* -----------------------------------------------------------
   Layout
   ----------------------------------------------------------- */

.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid #000;
    display: flex;
    flex-direction: column;
}

.sidebar__brand {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0 1.5rem 2rem;
    border-bottom: 1px solid #242420;
    margin-bottom: 1rem;
}
.sidebar__brand-mark {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 500;
    font-style: italic;
    color: var(--accent);
    line-height: 1;
    font-variation-settings: "SOFT" 100;
}
.sidebar__brand-name {
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}

.sidebar__section {
    padding: 0.5rem 1.5rem;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    margin-top: 0.5rem;
}

.sidebar__nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 1.5rem;
    color: var(--sidebar-ink);
    font-size: 0.9375rem;
    border-left: 2px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}
.sidebar__nav a:hover {
    background: var(--sidebar-hover);
    text-decoration: none;
}
.sidebar__nav a.is-active {
    background: var(--sidebar-active);
    border-left-color: var(--accent);
    color: #fff;
}
.sidebar__nav .badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.sidebar__user {
    margin-top: auto;
    padding: 1rem 1.5rem 0;
    border-top: 1px solid #242420;
}
.sidebar__user-name { color: #fff; font-size: 0.875rem; font-weight: 500; }
.sidebar__user-email { color: var(--sidebar-muted); font-size: 0.8rem; }
.sidebar__user a { color: var(--sidebar-muted); font-size: 0.8rem; }

/* Main area */
.main { min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-raised);
}
.topbar__title { display: flex; flex-direction: column; gap: 0.15rem; }
.topbar__eyebrow { font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-muted); }
.topbar__actions { display: flex; gap: 0.5rem; }

.content { padding: 2rem 2.5rem 4rem; max-width: 1400px; }
.content--narrow { max-width: 720px; }

/* -----------------------------------------------------------
   Cards & Tables
   ----------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card + .card { margin-top: 1.5rem; }
.card__header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}
.card__title { font-family: var(--font-display); font-size: 1.125rem; font-weight: 500; }
.card__body  { padding: 1.25rem; }

.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
}
.stat__label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-muted);
    margin-bottom: 0.5rem;
}
.stat__value {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 400;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}
.stat__hint {
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin-top: 0.35rem;
}
.stat--accent { background: linear-gradient(135deg, #0E7C66 0%, #0A5A4A 100%); color: #fff; border-color: transparent; }
.stat--accent .stat__label, .stat--accent .stat__hint { color: rgba(255,255,255,0.75); }
.stat--accent .stat__value { color: #fff; }
.stat--danger { background: var(--danger-soft); border-color: #E9CDC1; }
.stat--warn   { background: var(--warn-soft);   border-color: #E8D2A8; }

/* Tables */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
}
.table th {
    text-align: left;
    font-weight: 500;
    color: var(--ink-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #FBF8F1;
}
.table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #FBF8F1; }
.table .mono { color: var(--ink-soft); }

.table__empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--ink-muted);
}
.table__empty h3 { font-family: var(--font-display); font-style: italic; color: var(--ink-soft); margin-bottom: 0.5rem; }

/* -----------------------------------------------------------
   Badges
   ----------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 500;
    border: 1px solid transparent;
}
.badge--ok   { background: var(--success-soft); color: var(--accent-dark); }
.badge--warn { background: var(--warn-soft);    color: #7B5620; }
.badge--err  { background: var(--danger-soft);  color: var(--danger); }
.badge--muted { background: #EEE9DB; color: var(--ink-soft); }
.badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* -----------------------------------------------------------
   Forms & buttons
   ----------------------------------------------------------- */

.form-row { margin-bottom: 1.25rem; }
.form-row--split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--ink-soft); margin-bottom: 0.4rem; letter-spacing: 0.02em; }
label .hint { font-weight: 400; color: var(--ink-muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="datetime-local"], input[type="file"], select, textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 0.9375rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { font-family: var(--font-body); min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 124, 102, 0.15);
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}
.checkbox input { width: auto; margin: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--ink);
    color: #fff;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.05s, background 0.15s, box-shadow 0.15s;
}
.btn:hover { background: #000; text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn--primary { background: var(--accent); }
.btn--primary:hover { background: var(--accent-dark); }

.btn--ghost {
    background: transparent;
    color: var(--ink);
    border-color: var(--border-strong);
}
.btn--ghost:hover { background: #F0EBDD; }

.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #8C2F1F; }

.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.btn-group form { display: inline-block; margin: 0; }
.btn-group { display: inline-flex; gap: 0.4rem; }

/* -----------------------------------------------------------
   Flash messages
   ----------------------------------------------------------- */

.flash-stack { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border-left: 3px solid;
    font-size: 0.9rem;
}
.flash--success { background: var(--success-soft); border-color: var(--accent); color: var(--accent-dark); }
.flash--error   { background: var(--danger-soft);  border-color: var(--danger); color: var(--danger); }

/* -----------------------------------------------------------
   Login page
   ----------------------------------------------------------- */

.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    background:
      radial-gradient(ellipse at 20% 10%, rgba(14, 124, 102, 0.08) 0%, transparent 50%),
      radial-gradient(ellipse at 80% 90%, rgba(192, 136, 68, 0.08) 0%, transparent 50%),
      var(--bg);
}
.login__card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow);
}
.login__brand {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 500;
    font-style: italic;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 0.25rem;
    font-variation-settings: "SOFT" 100;
}
.login__tag {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.25em;
    color: var(--ink-muted);
    margin-bottom: 2rem;
}

/* -----------------------------------------------------------
   Pagination
   ----------------------------------------------------------- */

.pagination {
    display: flex;
    gap: 0.3rem;
    margin-top: 1rem;
    justify-content: flex-end;
    align-items: center;
    color: var(--ink-muted);
    font-size: 0.85rem;
}
.pagination a, .pagination span {
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--ink-soft);
    text-decoration: none;
}
.pagination a:hover { background: #F0EBDD; }
.pagination .is-current { background: var(--ink); color: #fff; border-color: var(--ink); }

/* -----------------------------------------------------------
   Chat / Inbox
   ----------------------------------------------------------- */

.chat {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    min-height: 75vh;
}
.chat__list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.chat__item {
    display: block;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--ink);
    text-decoration: none;
}
.chat__item:hover { background: #FBF8F1; text-decoration: none; }
.chat__item-name { font-weight: 500; font-size: 0.95rem; }
.chat__item-preview { color: var(--ink-muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat__thread {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
}
.chat__header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat__body {
    flex: 1;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    background: #FBF8F1;
    max-height: 55vh;
}
.bubble {
    max-width: 70%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.35;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}
.bubble--in {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.bubble--out {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble__meta {
    font-size: 0.7rem;
    margin-top: 0.25rem;
    opacity: 0.75;
    display: flex;
    gap: 0.4rem;
}
.chat__composer {
    border-top: 1px solid var(--border);
    padding: 1rem;
    background: var(--bg-raised);
}
.chat__composer textarea { min-height: 72px; }
.window-info {
    padding: 0.5rem 0.85rem;
    background: var(--warn-soft);
    border-left: 3px solid var(--warn);
    font-size: 0.85rem;
    color: #7B5620;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
}
.window-info--ok { background: var(--success-soft); border-left-color: var(--accent); color: var(--accent-dark); }

/* -----------------------------------------------------------
   Misc
   ----------------------------------------------------------- */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.toolbar__search { display: flex; gap: 0.4rem; }
.toolbar__search input { min-width: 260px; }

.muted { color: var(--ink-muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--ink-muted);
}
.empty h3 { font-style: italic; margin-bottom: 0.5rem; }

/* Mini sparkline / bar chart */
.barchart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 90px;
    padding: 0.5rem 0;
}
.barchart__col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.65rem;
    color: var(--ink-muted);
}
.barchart__bar {
    width: 100%;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: opacity 0.12s;
}
.barchart__bar--in { background: var(--border-strong); }
.barchart__col:hover .barchart__bar { opacity: 0.8; }

/* Responsive */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .content { padding: 1.25rem; }
    .chat { grid-template-columns: 1fr; }
}
