@import url("https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=JetBrains+Mono:wght@400&display=swap");

/* ─────────────────────────────────────────────
   TOKENS
───────────────────────────────────────────── */
:root {
    --bg:         #07101F;
    --bg_surface: #0C1726;
    --bg_card:    #101F33;
    --bg_inset:   #0D1929;
    --border:       #1C2E44;
    --border_hi:    #263D58;
    --text_hi:    #EDF2F7;
    --text_body:  #8FA8C2;
    --text_muted: #4D6880;
    --green:    #0BDA8A;
    --green_lo: rgba(11,218,138,0.08);
    --green_md: rgba(11,218,138,0.15);
    --green_hi: rgba(11,218,138,0.25);
    --amber:    #F0A030;
    --amber_lo: rgba(240,160,48,0.1);
    --blue:     #4A9EFF;
    --blue_lo:  rgba(74,158,255,0.1);
    --red:      #EF4444;
    --red_lo:   rgba(239,68,68,0.1);
    --font_body: 'DM Sans', system-ui, sans-serif;
    --font_code: 'JetBrains Mono', monospace;
    --r_sm: 6px;
    --r_md: 10px;
    --r_lg: 16px;
    --ease_f: 0.18s ease;
    --ease_m: 0.3s ease;
    --nav_w: 220px;
    --top_h: 56px;
    --shadow: 0 2px 16px rgba(0,0,0,0.3);
}

/* ─────────────────────────────────────────────
   RESET
───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font_body); background: var(--bg); color: var(--text_body); line-height: 1.65; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
img  { max-width: 100%; height: auto; display: block; }
a    { color: inherit; text-decoration: none; }
ul   { list-style: none; }
button { font-family: inherit; cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 3px; }

/* ─────────────────────────────────────────────
   LOGIN PAGE
───────────────────────────────────────────── */
.login_page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: radial-gradient(ellipse at 30% 20%, rgba(11,218,138,0.06) 0%, transparent 60%);
}

.login_card {
    width: 100%;
    max-width: 380px;
    background: var(--bg_surface);
    border: 1px solid var(--border);
    border-radius: var(--r_lg);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow);
}

.login_logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text_hi);
    margin-bottom: 0.25rem;
}
.login_logo span { color: var(--green); }
.login_sub { font-size: 0.8rem; color: var(--text_muted); margin-bottom: 2rem; }

.login_error {
    background: var(--red_lo);
    border: 1px solid rgba(239,68,68,0.25);
    color: var(--red);
    border-radius: var(--r_sm);
    padding: 0.55rem 0.8rem;
    font-size: 0.82rem;
    margin-bottom: 1rem;
    display: none;
}
.login_error.visible { display: block; }

/* ─────────────────────────────────────────────
   LAYOUT — sidebar + main
───────────────────────────────────────────── */
.admin_layout {
    display: grid;
    grid-template-columns: var(--nav_w) 1fr;
    grid-template-rows: var(--top_h) 1fr;
    min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background: var(--bg_surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar_logo { font-size: 1rem; font-weight: 700; color: var(--text_hi); flex: 1; }
.topbar_logo span { color: var(--green); }
.topbar_user { font-size: 0.78rem; color: var(--text_muted); }
.topbar_logout_btn {
    font-size: 0.78rem;
    color: var(--text_muted);
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--r_sm);
    transition: color var(--ease_f), border-color var(--ease_f);
}
.topbar_logout_btn:hover { color: var(--red); border-color: var(--red); }

/* ── Sidebar ── */
.sidebar {
    background: var(--bg_surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0;
    position: sticky;
    top: var(--top_h);
    height: calc(100vh - var(--top_h));
    overflow-y: auto;
}
.nav_section_label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text_muted);
    padding: 0.85rem 1.25rem 0.35rem;
}
.nav_item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1.25rem;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text_body);
    border-radius: 0;
    transition: background var(--ease_f), color var(--ease_f);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.nav_item i { width: 16px; text-align: center; opacity: 0.7; }
.nav_item:hover { background: var(--bg_card); color: var(--text_hi); }
.nav_item.active { background: var(--green_lo); color: var(--green); border-right: 2px solid var(--green); }
.nav_item.active i { opacity: 1; }

/* ── Main content ── */
.main_content {
    padding: 1.75rem 2rem;
    overflow-y: auto;
    max-width: 1200px;
}

/* ─────────────────────────────────────────────
   SHARED SECTION CHROME
───────────────────────────────────────────── */
.section_panel { display: none; }
.section_panel.active { display: block; }

.section_topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.section_heading { font-size: 1.2rem; font-weight: 700; color: var(--text_hi); }
.section_sub { font-size: 0.8rem; color: var(--text_muted); margin-top: 0.2rem; }

.date_range_bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.date_range_bar label { font-size: 0.8rem; color: var(--text_muted); }

/* ─────────────────────────────────────────────
   CARDS
───────────────────────────────────────────── */
.card {
    background: var(--bg_card);
    border: 1px solid var(--border);
    border-radius: var(--r_md);
    padding: 1.25rem;
}
.card_title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text_hi);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ─────────────────────────────────────────────
   KPI ROW
───────────────────────────────────────────── */
.kpi_row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.kpi_card {
    background: var(--bg_card);
    border: 1px solid var(--border);
    border-radius: var(--r_md);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
}
.kpi_green { border-left: 3px solid var(--green); }
.kpi_blue  { border-left: 3px solid var(--blue);  }
.kpi_amber { border-left: 3px solid var(--amber); }
.kpi_icon  { font-size: 1.15rem; opacity: 0.6; }
.kpi_green .kpi_icon { color: var(--green); }
.kpi_blue  .kpi_icon { color: var(--blue);  }
.kpi_amber .kpi_icon { color: var(--amber); }
.kpi_value { display: block; font-size: 1.55rem; font-weight: 700; color: var(--text_hi); line-height: 1.2; }
.kpi_label { display: block; font-size: 0.73rem; color: var(--text_muted); margin-top: 0.1rem; }

/* ─────────────────────────────────────────────
   2-COLUMN GRID
───────────────────────────────────────────── */
.grid_2col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* ─────────────────────────────────────────────
   DEVICE BAR
───────────────────────────────────────────── */
.device_bar_wrap { padding-top: 0.5rem; }
.device_bar {
    display: flex;
    height: 14px;
    border-radius: 100px;
    overflow: hidden;
    background: var(--bg_inset);
    margin-bottom: 0.75rem;
}
.device_seg { height: 100%; transition: width 0.4s ease; }
.device_mobile  { background: var(--green); }
.device_desktop { background: var(--blue); }
.device_legend { font-size: 0.8rem; color: var(--text_body); }
.dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    vertical-align: middle;
}
.dot_mobile   { background: var(--green); }
.dot_desktop  { background: var(--blue);  }
.dot_visits   { background: var(--green); }
.dot_clicks   { background: var(--amber); }

/* ─────────────────────────────────────────────
   TREND CHART (SVG)
───────────────────────────────────────────── */
.trend_chart {
    width: 100%;
    overflow: visible;
}
.line_visits { stroke: var(--green); stroke-width: 2; }
.line_clicks { stroke: var(--amber); stroke-width: 2; stroke-dasharray: 4 2; }
.chart_label { font-size: 9px; fill: var(--text_muted); font-family: var(--font_body); }
.chart_legend { font-size: 0.75rem; color: var(--text_body); margin-top: 0.5rem; }

/* ─────────────────────────────────────────────
   BAR LIST
───────────────────────────────────────────── */
.bar_list { display: flex; flex-direction: column; gap: 0.45rem; }
.bar_row  { display: flex; align-items: center; gap: 0.6rem; font-size: 0.8rem; }
.bar_label { width: 90px; flex-shrink: 0; color: var(--text_body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar_track { flex: 1; height: 8px; background: var(--bg_inset); border-radius: 100px; overflow: hidden; }
.bar_fill  { height: 100%; background: var(--green); border-radius: 100px; transition: width 0.35s ease; }
.bar_num   { width: 36px; text-align: right; color: var(--text_muted); font-size: 0.75rem; }

/* ─────────────────────────────────────────────
   TABLES
───────────────────────────────────────────── */
.table_wrap { overflow-x: auto; border-radius: var(--r_md); border: 1px solid var(--border); }
.data_table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.data_table th {
    text-align: left;
    padding: 0.55rem 0.85rem;
    background: var(--bg_inset);
    color: var(--text_muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data_table td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text_body);
    vertical-align: top;
}
.data_table tbody tr:last-child td { border-bottom: none; }
.data_table tbody tr:hover td { background: var(--bg_inset); }
.num_cell  { text-align: right; font-variant-numeric: tabular-nums; }
.pct_cell  { text-align: right; color: var(--text_muted); font-size: 0.76rem; }
.date_cell { white-space: nowrap; }
.ref_cell  { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─────────────────────────────────────────────
   CONTACTS TABLE
───────────────────────────────────────────── */
.contact_name_btn {
    background: none;
    border: none;
    color: var(--text_hi);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0;
    text-align: left;
}
.expand_icon { font-size: 0.65rem; color: var(--text_muted); transition: transform var(--ease_f); }
.contact_email { font-size: 0.75rem; color: var(--text_muted); margin-top: 0.15rem; }

.detail_panel {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1.25rem;
    padding: 0.9rem 0.5rem;
    background: var(--bg_inset);
    border-radius: var(--r_sm);
}
.detail_message p { font-size: 0.82rem; line-height: 1.7; white-space: pre-wrap; color: var(--text_body); }
.detail_meta { display: flex; flex-direction: column; gap: 0.45rem; min-width: 200px; }
.detail_meta > div { display: flex; flex-direction: column; gap: 0.1rem; }
.detail_label { font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text_muted); font-weight: 600; }
.mono_text { font-family: var(--font_code); font-size: 0.72rem; color: var(--text_body); word-break: break-all; }

/* ─────────────────────────────────────────────
   BADGES
───────────────────────────────────────────── */
.status_badge {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.status_new     { background: var(--green_lo);  color: var(--green); }
.status_read    { background: var(--blue_lo);   color: var(--blue);  }
.status_replied { background: rgba(148,163,184,0.12); color: var(--text_muted); }

.badge       { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 100px; font-size: 0.7rem; font-weight: 600; }
.badge_ok    { background: var(--green_lo); color: var(--green); }
.badge_warn  { background: var(--amber_lo); color: var(--amber); }

.category_tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--r_sm);
    font-size: 0.7rem;
    background: var(--bg_inset);
    color: var(--text_muted);
    border: 1px solid var(--border);
}
.type_badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--r_sm);
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 0.4rem;
}
.type_notification    { background: var(--blue_lo);  color: var(--blue);  }
.type_acknowledgement { background: var(--green_lo); color: var(--green); }

.flag_text { font-size: 0.8rem; font-weight: 600; color: var(--text_hi); }

/* ─────────────────────────────────────────────
   BUTTONS
───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--r_sm);
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--ease_f), color var(--ease_f), border-color var(--ease_f), opacity var(--ease_f);
    border: 1px solid transparent;
    background: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn_primary { background: var(--green); color: #07101F; border-color: var(--green); }
.btn_primary:hover:not(:disabled) { opacity: 0.88; }
.btn_ghost {
    background: transparent;
    color: var(--text_body);
    border-color: var(--border_hi);
}
.btn_ghost:hover:not(:disabled) { background: var(--bg_inset); color: var(--text_hi); }
.btn_sm  { padding: 0.38rem 0.75rem; font-size: 0.76rem; }
.btn_xs  { padding: 0.22rem 0.55rem; font-size: 0.72rem; }
.action_btns { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* ─────────────────────────────────────────────
   FORM ELEMENTS
───────────────────────────────────────────── */
.form_group { margin-bottom: 1rem; }
.form_label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text_body); margin-bottom: 0.35rem; }
.form_input, .form_select, .form_textarea {
    width: 100%;
    background: var(--bg_inset);
    border: 1px solid var(--border);
    border-radius: var(--r_sm);
    color: var(--text_hi);
    font-family: var(--font_body);
    font-size: 0.83rem;
    padding: 0.55rem 0.8rem;
    transition: border-color var(--ease_f);
}
.form_input:focus, .form_select:focus, .form_textarea:focus {
    border-color: var(--green);
    outline: none;
}
.form_textarea { resize: vertical; line-height: 1.6; }
.code_textarea { font-family: var(--font_code); font-size: 0.75rem; }

/* ─────────────────────────────────────────────
   FILTERS BAR
───────────────────────────────────────────── */
.filters_bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg_card);
    border: 1px solid var(--border);
    border-radius: var(--r_md);
}
.filter_select, .filter_input {
    background: var(--bg_inset);
    border: 1px solid var(--border);
    color: var(--text_hi);
    font-family: var(--font_body);
    font-size: 0.8rem;
    padding: 0.38rem 0.65rem;
    border-radius: var(--r_sm);
    flex: 1;
    min-width: 110px;
}

/* ─────────────────────────────────────────────
   LIST HEADER + PAGINATION
───────────────────────────────────────────── */
.list_header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.list_summary { font-size: 0.8rem; color: var(--text_muted); }
.pagination { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; }
.page_info { font-size: 0.8rem; color: var(--text_muted); }

/* ─────────────────────────────────────────────
   EMAIL TEMPLATES
───────────────────────────────────────────── */
.templates_grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.template_card {
    background: var(--bg_card);
    border: 1px solid var(--border);
    border-radius: var(--r_md);
    padding: 1.1rem 1.25rem;
}
.template_header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}
.template_subject { font-size: 0.82rem; color: var(--text_body); margin-bottom: 0.3rem; }
.template_updated { font-size: 0.73rem; }
.template_editor  { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.editor_tabs { display: flex; gap: 0; margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.editor_tab {
    padding: 0.35rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text_muted);
    border-radius: var(--r_sm) var(--r_sm) 0 0;
    transition: color var(--ease_f), background var(--ease_f);
}
.editor_tab.active { color: var(--green); border-bottom: 2px solid var(--green); }
.editor_actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; justify-content: flex-end; }
.html_preview {
    background: var(--bg_inset);
    border: 1px solid var(--border);
    border-radius: var(--r_sm);
    padding: 0.75rem;
    min-height: 120px;
    font-size: 0.8rem;
    max-height: 420px;
    overflow-y: auto;
}

/* ─────────────────────────────────────────────
   COMPOSE MODAL
───────────────────────────────────────────── */
.modal_overlay {
    position: fixed;
    inset: 0;
    background: rgba(7,16,31,0.72);
    backdrop-filter: blur(3px);
    z-index: 200;
}
.compose_modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(600px, calc(100vw - 2rem));
    max-height: calc(100vh - 4rem);
    background: var(--bg_surface);
    border: 1px solid var(--border_hi);
    border-radius: var(--r_lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 201;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal_header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal_title { font-size: 0.95rem; font-weight: 700; color: var(--text_hi); }
.modal_close_btn { color: var(--text_muted); font-size: 1.1rem; transition: color var(--ease_f); }
.modal_close_btn:hover { color: var(--text_hi); }
.modal_body { padding: 1.1rem 1.25rem; overflow-y: auto; flex: 1; }
.modal_footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.compose_recipient { font-size: 0.82rem; color: var(--text_body); margin-bottom: 1rem; }
.compose_hint { font-size: 0.77rem; margin-bottom: 1rem; }

/* ─────────────────────────────────────────────
   LOADING SPINNER
───────────────────────────────────────────── */
.spinner_wrap { display: flex; justify-content: center; padding: 2rem 0; }
.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────
   TOAST
───────────────────────────────────────────── */
.admin_toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--bg_surface);
    border: 1px solid var(--border_hi);
    color: var(--text_hi);
    border-radius: var(--r_sm);
    padding: 0.65rem 1.1rem;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    transform: translateY(80px);
    opacity: 0;
    transition: transform var(--ease_m), opacity var(--ease_m);
    z-index: 300;
    max-width: 320px;
}
.admin_toast.toast_show { transform: translateY(0); opacity: 1; }
.toast_success { border-left: 3px solid var(--green); }
.toast_error   { border-left: 3px solid var(--red);   }
.toast_info    { border-left: 3px solid var(--blue);  }

/* ─────────────────────────────────────────────
   MISC UTILS
───────────────────────────────────────────── */
.text_muted { color: var(--text_muted); }
.text_hi    { color: var(--text_hi); }
.empty_msg  { color: var(--text_muted); font-size: 0.82rem; padding: 1.5rem 0; text-align: center; }
.error_msg  { color: var(--red); font-size: 0.82rem; padding: 1rem 0; }

/* ─────────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --nav_w: 0px; }
    .admin_layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main_content { padding: 1rem; }
    .kpi_row { grid-template-columns: 1fr 1fr; }
    .detail_panel { grid-template-columns: 1fr; }
    .detail_meta { min-width: 0; }
}

@media print {
    .sidebar, .topbar, .btn, .filters_bar, .pagination, .action_btns,
    .editor_actions, .modal_overlay, .compose_modal, #adminToast { display: none !important; }
    body { background: #fff; color: #0f172a; }
    .card, .data_table, .kpi_card { border-color: #e2e8f0; }
    th { background: #f8fafc !important; }
}
