/* assets/css/main.css */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500&family=DM+Mono:wght@400;500&display=swap');

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

:root {
    --bg:         #f5f5f4;
    --surface:    #ffffff;
    --border:     #e5e5e3;
    --border-2:   #d4d4d2;
    --text-1:     #1a1a1a;
    --text-2:     #6b6b6b;
    --text-3:     #9b9b9b;
    --accent:     #16a34a;
    --accent-bg:  #f0fdf4;
    --accent-2:   #0f766e;
    --danger:     #dc2626;
    --danger-bg:  #fef2f2;
    --warn:       #d97706;
    --warn-bg:    #fffbeb;
    --info:       #2563eb;
    --info-bg:    #eff6ff;
    --radius:     8px;
    --radius-lg:  12px;
    --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.08);
    --font:       'DM Sans', sans-serif;
    --font-mono:  'DM Mono', monospace;
    --nav-w:      220px;
    --header-h:   56px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-1);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Auth Layout ---- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}
.auth-logo {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-1);
    margin-bottom: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.auth-logo span {
    display: inline-block;
    width: 28px; height: 28px;
    background: var(--accent);
    border-radius: 6px;
}
.auth-title { font-size: 20px; font-weight: 500; margin-bottom: 4px; }
.auth-sub   { color: var(--text-2); margin-bottom: 28px; font-size: 13px; }
.auth-switch { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-2); }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ---- Dashboard Layout ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--nav-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 18px 20px;
    font-size: 15px;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-1);
    text-decoration: none;
}
.sidebar-logo span {
    display: inline-block;
    width: 24px; height: 24px;
    background: var(--accent);
    border-radius: 5px;
    flex-shrink: 0;
}

.nav-section { padding: 16px 12px 8px; }
.nav-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 0 8px;
    margin-bottom: 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--text-2);
    text-decoration: none;
    font-size: 13.5px;
    transition: background .15s, color .15s;
    margin-bottom: 2px;
    cursor: pointer;
}
.nav-item:hover  { background: var(--bg); color: var(--text-1); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-item svg    { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.75; }

.sidebar-footer {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid var(--border);
}
.user-pill {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s;
}
.user-pill:hover { background: var(--bg); }
.user-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name  { font-size: 12.5px; font-weight: 500; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Main Content ---- */
.main {
    margin-left: var(--nav-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title { font-size: 15px; font-weight: 500; }
.topbar-right  { display: flex; align-items: center; gap: 10px; }

.page-body { padding: 24px; flex: 1; }

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-2); margin-bottom: 8px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 400; color: var(--text-1); line-height: 1; }
.stat-delta { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.stat-delta.up   { color: var(--accent); }
.stat-delta.down { color: var(--danger); }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title { font-size: 14px; font-weight: 500; }
.card-body  { padding: 20px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead tr { border-bottom: 1px solid var(--border); }
th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-3);
    white-space: nowrap;
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text-1); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ---- Forms ---- */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; font-size: 13px; font-weight: 500; color: var(--text-1); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-1);
    background: var(--surface);
    transition: border .15s, box-shadow .15s;
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity .15s, background .15s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover   { opacity: .88; }
.btn:active  { opacity: .75; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg     { width: 15px; height: 15px; stroke-width: 2; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text-1); border: 1px solid var(--border-2); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-2); }
.btn-sm      { padding: 5px 12px; font-size: 12.5px; }
.btn-lg      { padding: 11px 22px; font-size: 15px; width: 100%; justify-content: center; }
.btn-icon    { padding: 7px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--border); color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; transition: background .15s; }
.btn-icon:hover { background: var(--border); }

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-green  { background: var(--accent-bg);  color: var(--accent); }
.badge-red    { background: var(--danger-bg);   color: var(--danger); }
.badge-yellow { background: var(--warn-bg);     color: var(--warn); }
.badge-blue   { background: var(--info-bg);     color: var(--info); }
.badge-gray   { background: var(--bg);          color: var(--text-2); border: 1px solid var(--border); }

/* ---- Alerts ---- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin-bottom: 16px;
    display: none;
}
.alert.show  { display: block; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--accent-bg); color: var(--accent); border: 1px solid #bbf7d0; }
.alert-info  { background: var(--info-bg); color: var(--info); border: 1px solid #bfdbfe; }

/* ---- Modal ---- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    animation: modal-in .15s ease;
}
@keyframes modal-in {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
}
.modal-header {
    padding: 18px 22px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title  { font-size: 15px; font-weight: 500; }
.modal-body   { padding: 18px 22px; }
.modal-footer { padding: 0 22px 18px; display: flex; justify-content: flex-end; gap: 10px; }
.modal-close  { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px; }
.modal-close:hover { color: var(--text-1); }

/* ---- Toast ---- */
#toast-container {
    position: fixed;
    bottom: 24px; right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}
.toast {
    background: var(--text-1);
    color: #fff;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 13.5px;
    max-width: 320px;
    box-shadow: var(--shadow-md);
    animation: toast-in .2s ease;
    display: flex;
    align-items: center;
    gap: 9px;
}
@keyframes toast-in {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
}
.toast.success { background: var(--accent); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--info);   }

/* ---- Misc ---- */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty-state h3 { font-size: 15px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.page-header { margin-bottom: 22px; }
.page-title  { font-size: 18px; font-weight: 500; }
.page-desc   { color: var(--text-2); font-size: 13px; margin-top: 3px; }
.flex        { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2       { gap: 8px; }
.gap-3       { gap: 12px; }
.mb-4        { margin-bottom: 16px; }
.mb-6        { margin-bottom: 24px; }
.grid-2      { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.text-muted  { color: var(--text-2); }
.text-sm     { font-size: 12px; }
.mono        { font-family: var(--font-mono); }
.loading-spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

/* ============================================
   RESPONSIVE — Mobile & Tablet
   ============================================ */

/* Tablet: 768px - 1024px */
@media (max-width: 1024px) {
    :root { --nav-w: 200px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

/* Mobile: up to 767px */
@media (max-width: 767px) {

    /* ---- Sidebar: hidden by default, slide-in overlay ---- */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 300;
        box-shadow: 4px 0 24px rgba(0,0,0,.12);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 299;
    }
    .sidebar-overlay.open { display: block; }

    /* ---- Main shifts to full width ---- */
    .main { margin-left: 0; }

    /* ---- Topbar: add hamburger ---- */
    .topbar { padding: 0 14px; }
    .topbar-title { font-size: 14px; }

    /* ---- Page body ---- */
    .page-body { padding: 14px; }

    /* ---- Stats grid: 2 col on mobile ---- */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 16px;
    }
    .stat-value { font-size: 20px; }

    /* ---- Cards ---- */
    .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
    .card-body { padding: 14px; }

    /* ---- Grid layouts ---- */
    .grid-2 { grid-template-columns: 1fr; gap: 14px; }
    .form-row { grid-template-columns: 1fr; gap: 0; }

    /* ---- Page header ---- */
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
        margin-bottom: 16px;
    }
    .page-header .flex { flex-wrap: wrap; gap: 6px; }

    /* ---- Tables: horizontal scroll ---- */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 520px; }
    th, td { padding: 9px 10px; white-space: nowrap; }

    /* ---- Modal ---- */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal {
        max-width: 100% !important;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 92vh;
    }

    /* ---- Auth ---- */
    .auth-card { padding: 24px 20px; margin: 16px; }

    /* ---- Buttons wrap ---- */
    .topbar-right { gap: 6px; }
    .btn-sm { padding: 5px 10px; font-size: 12px; }

    /* ---- Filter bars ---- */
    .card-body .flex { flex-wrap: wrap; }

    /* ---- Chatbot builder: stack on mobile ---- */
    #builder-modal .modal { grid-template-columns: 1fr !important; }

    /* ---- Toast: full width ---- */
    #toast-container { left: 12px; right: 12px; bottom: 12px; }
    .toast { max-width: 100%; }
}

/* Small mobile: up to 480px */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-value { font-size: 18px; }
    .stat-label { font-size: 10px; }
    .page-title { font-size: 16px; }
    .card-title { font-size: 13px; }
    .auth-card { padding: 20px 16px; }
    .modal-header { padding: 14px 16px 0; }
    .modal-body { padding: 14px 16px; }
    .modal-footer { padding: 0 16px 14px; }
}
