/* =========================================================================
   Gridkast CRM — premium SaaS dashboard theme
   Navy structure · off-white base · indigo accent
   ========================================================================= */
:root {
    /* Brand */
    --navy-900: #0b1220;
    --navy-800: #101a2e;
    --navy-700: #16233d;
    --navy-600: #1e2f4d;
    --accent:      #4f46e5;
    --accent-600:  #4338ca;
    --accent-050:  #eef2ff;

    /* Neutrals */
    --bg:        #f6f7f9;
    --surface:   #ffffff;
    --surface-2: #fbfbfd;
    --line:      #e6e8ee;
    --line-2:    #eef0f4;
    --ink:       #111827;
    --ink-2:     #374151;
    --muted:     #6b7280;
    --muted-2:   #9aa1ad;

    /* Semantic */
    --success: #059669; --success-bg: #ecfdf5;
    --warning: #d97706; --warning-bg: #fffbeb;
    --danger:  #dc2626; --danger-bg:  #fef2f2;
    --info:    #2563eb; --info-bg:    #eff6ff;

    --radius:    14px;
    --radius-sm: 10px;
    --shadow:   0 1px 2px rgba(16,24,40,.04);
    --shadow-lg:0 12px 32px rgba(16,24,40,.12);
    --sidebar-w: 258px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
.icon { flex: 0 0 auto; }

/* ---------- Layout shell ------------------------------------------------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; padding: 26px 30px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* ---------- Sidebar ------------------------------------------------------ */
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: var(--navy-900);
    color: #c7cede; display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 20px 14px; }
.brand-link { display: flex; align-items: center; gap: 11px; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; }
.brand-text { font-size: 19px; font-weight: 800; color: #fff; letter-spacing: -.02em; }
.brand-dot { color: var(--accent); }
.nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 1px; }
.nav-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #5c6b8a; font-weight: 700; margin: 14px 12px 4px; }
.nav-group-label:first-child { margin-top: 4px; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #24314c; border-radius: 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-radius: 10px;
    color: #9aa7c0; font-weight: 500; font-size: 13.5px;
    transition: background .15s, color .15s;
}
.nav-item .icon { width: 18px; height: 18px; }
.nav-item:hover { background: var(--navy-700); color: #e7ecf6; }
.nav-item.is-active { background: var(--accent); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.nav-item.is-active .nav-icon { color: #fff; }
.nav-icon { display: inline-flex; opacity: .95; }
.sidebar-foot { padding: 12px; }
.sidebar-card {
    background: var(--navy-700); border: 1px solid #223050;
    border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.sidebar-card strong { color: #fff; font-size: 13px; }
.sidebar-card span { color: #8592ad; font-size: 11.5px; }
.sidebar-scrim { display: none; }

/* ---------- Top bar ------------------------------------------------------ */
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 30px; background: var(--surface);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
}
.topbar-title h1 { font-size: 18px; }
.topbar-title p { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-search {
    margin-left: auto; display: flex; align-items: center; gap: 8px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 10px; padding: 8px 12px; width: 320px; color: var(--muted);
}
.topbar-search input { border: 0; background: none; outline: none; width: 100%; font-size: 13.5px; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink-2); cursor: pointer; transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.dot-count {
    position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px;
    padding: 0 4px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700;
    border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.menu-toggle { display: none; }

/* user menu */
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 3px 4px; }
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.user-role { font-size: 11px; color: var(--muted); }
.user-dropdown {
    position: absolute; right: 0; top: 48px; background: var(--surface);
    border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
    min-width: 180px; padding: 6px; display: none; z-index: 40;
}
.user-dropdown.open { display: block; }
.user-dropdown a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px; color: var(--ink-2); }
.user-dropdown a:hover { background: var(--surface-2); }
.user-dropdown a.danger { color: var(--danger); }

/* ---------- Avatars ------------------------------------------------------ */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    background: hsl(var(--h,230) 65% 94%); color: hsl(var(--h,230) 55% 38%);
    font-weight: 700; border-radius: 50%; flex: 0 0 auto;
}
.avatar-sm { width: 34px; height: 34px; font-size: 12.5px; }
.avatar-xs { width: 26px; height: 26px; font-size: 10.5px; }
.avatar-empty { background: var(--line-2); color: var(--muted-2); }

/* ---------- Cards -------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 18px; border-bottom: 1px solid var(--line-2);
}
.card-head h3 { font-size: 15px; }
.card-actions { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

/* ---------- Stat cards --------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.stat-icon {
    width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    background: var(--accent-050); color: var(--accent); flex: 0 0 auto;
}
.stat-body { display: flex; flex-direction: column; }
.stat-value { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }
.tone-success .stat-icon { background: var(--success-bg); color: var(--success); }
.tone-warning .stat-icon { background: var(--warning-bg); color: var(--warning); }
.tone-danger  .stat-icon { background: var(--danger-bg);  color: var(--danger); }
.tone-info    .stat-icon { background: var(--info-bg);    color: var(--info); }

/* ---------- Grouped mini-metrics ---------------------------------------- */
.metric-group { margin-bottom: 22px; }
.metric-group > .mg-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 0 0 10px 2px; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.mini-stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 13px 15px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.mini-stat .mv { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.mini-stat .ml { font-size: 12px; color: var(--muted); font-weight: 500; }
.mini-stat.alert-danger-tone { border-color: #f6cccc; }
.mini-stat.alert-danger-tone .mv { color: var(--danger); }
.mini-stat.alert-warn-tone .mv { color: var(--warning); }
.mini-stat.good-tone .mv { color: var(--success); }
.mini-stat a { color: inherit; }

/* ---------- Badges ------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    line-height: 1.4; white-space: nowrap;
}
.badge-primary { background: var(--accent-050); color: var(--accent-600); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-muted   { background: #f1f3f6; color: var(--muted); }

/* ---------- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; transition: background .15s, box-shadow .15s;
    background: var(--surface); color: var(--ink);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-600); }
.btn-dark { background: var(--navy-800); color: #fff; }
.btn-dark:hover { background: var(--navy-700); }
.btn-outline { border-color: var(--line); background: var(--surface); color: var(--ink-2); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* icon-only table action */
.act {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
    border-radius: 8px; border: 1px solid var(--line); color: var(--muted); background: var(--surface);
}
.act:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data thead th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; padding: 12px 16px; background: var(--surface-2);
    border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td .sub { color: var(--muted); font-size: 12px; }
.cell-primary { font-weight: 600; color: var(--ink); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.hot-row { box-shadow: inset 3px 0 0 var(--danger); }

/* ---------- Filter bar --------------------------------------------------- */
.filters {
    display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 18px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
}
.filters .field { margin: 0; }
.filters .field label { font-size: 11px; }
.filters .grow { flex: 1; min-width: 160px; }

/* ---------- Forms -------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.input, .select, textarea.input, select, input[type=text], input[type=email], input[type=tel],
input[type=number], input[type=date], input[type=datetime-local], input[type=password], input[type=search] {
    width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
    font-size: 13.5px; font-family: var(--font); color: var(--ink); background: var(--surface); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, select:focus, textarea:focus, input:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-050);
}
textarea.input { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line-2); }

/* ---------- Alerts ------------------------------------------------------- */
.alert {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.alert-error   { background: var(--danger-bg);  color: #991b1b; border-color: #fecaca; }
.alert-info    { background: var(--info-bg);    color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.alert-close { background: none; border: 0; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }

/* ---------- Page header row --------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head > form { margin: 0; }
.page-head > form select { width: auto; min-width: 190px; }
.section-title { font-size: 14px; font-weight: 700; margin: 26px 0 12px; color: var(--ink); }

/* ---------- Grids -------------------------------------------------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-sidebar { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }

/* ---------- Timeline ----------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 4px 0 4px 4px; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before {
    content: ''; position: absolute; left: 4px; top: 4px; width: 10px; height: 10px;
    border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-050);
}
.timeline li::after { content: ''; position: absolute; left: 8px; top: 14px; bottom: -2px; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .tl-action { font-weight: 600; font-size: 13px; }
.timeline .tl-meta { color: var(--muted); font-size: 12px; }
.timeline .tl-detail { color: var(--ink-2); font-size: 13px; margin-top: 2px; }

/* ---------- Kanban pipeline --------------------------------------------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kan-col { flex: 0 0 260px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.kan-col h4 { font-size: 12.5px; padding: 12px 14px; display: flex; justify-content: space-between; color: var(--ink-2); }
.kan-col .count { color: var(--muted); font-weight: 600; }
.kan-list { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.kan-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.kan-card .kc-name { font-weight: 600; font-size: 13px; }
.kan-card .kc-meta { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; justify-content: space-between; }

/* ---------- Meta / definition lists ------------------------------------- */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; font-size: 13.5px; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; color: var(--ink); font-weight: 500; }

/* ---------- Empty / error states ---------------------------------------- */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; color: var(--muted-2); }
.empty-state .icon { width: 34px; height: 34px; opacity: .6; }
.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 64px; color: var(--accent); }
.error-page h2 { margin: 6px 0; }
.error-page p { color: var(--muted); margin-bottom: 20px; }

/* ---------- Pagination --------------------------------------------------- */
.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 14px 4px 4px; }
.page-btn { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--ink-2); background: var(--surface); }
.page-btn:hover { background: var(--surface-2); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn.disabled { opacity: .45; pointer-events: none; }
.page-ellipsis { padding: 0 4px; color: var(--muted); align-self: center; }

/* ---------- App footer --------------------------------------------------- */
.app-foot { display: flex; justify-content: space-between; padding: 16px 30px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* ---------- Modal -------------------------------------------------------- */
.modal-host { position: fixed; inset: 0; z-index: 100; display: none; }
.modal-host.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(11,18,32,.5); backdrop-filter: blur(2px); }
.modal {
    position: relative; max-width: 640px; width: calc(100% - 40px); margin: 60px auto;
    background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); max-height: 85vh; overflow: auto;
}

/* ---------- Login -------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand {
    background: radial-gradient(1200px 600px at 20% 10%, #1c2a49 0%, var(--navy-900) 60%);
    color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-brand .brand-text { font-size: 24px; }
.auth-brand h2 { color: #fff; font-size: 30px; line-height: 1.25; max-width: 460px; margin-top: 40px; }
.auth-brand p.lede { color: #9fb0d0; font-size: 15px; max-width: 440px; margin-top: 14px; }
.auth-features { display: flex; flex-direction: column; gap: 12px; margin-top: 30px; }
.auth-features span { color: #c7d2e8; font-size: 13.5px; display: flex; gap: 9px; align-items: center; }
.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; }
.auth-card .muted { color: var(--muted); margin: 6px 0 24px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.checkbox-row input { width: auto; }

/* ---------- Utilities ---------------------------------------------------- */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap-sm { gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }

/* ---------- Responsive --------------------------------------------------- */
@media (max-width: 1024px) {
    .grid-sidebar, .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .topbar-search { width: 210px; }
}
@media (max-width: 860px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
        transition: transform .22s ease;
    }
    .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .app.nav-open .sidebar-scrim { display: block; position: fixed; inset: 0; background: rgba(11,18,32,.4); z-index: 55; }
    .menu-toggle { display: inline-flex; }
    .content { padding: 18px 16px; }
    .topbar { padding: 12px 16px; }
    .topbar-search { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .user-meta { display: none; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
}
