/* ==========================================================================
   TS Clients — Licensing & Billing Portal
   Shared design system
   ========================================================================== */

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

:root {
    /* ---- Core palette --------------------------------------------- */
    --ink-900: #0c1024;
    --ink-800: #141a35;
    --ink-700: #1c2344;
    --canvas: #eef1f8;
    --surface: #ffffff;
    --surface-alt: #f6f8fc;
    --border: #e3e7f1;
    --border-soft: #edf0f7;

    /* ---- Brand ------------------------------------------------------ */
    --primary: #3454d1;
    --primary-dark: #2740a8;
    --primary-light: #e8ecfc;
    --gold: #b8862f;
    --gold-light: #faf1de;

    /* ---- Text --------------------------------------------------------- */
    --text: #161b33;
    --muted: #656c85;
    --muted-soft: #98a0b8;
    --on-dark: #cbd1e8;
    --on-dark-strong: #ffffff;

    /* ---- Status ------------------------------------------------------- */
    --success: #1f9d6c;
    --success-bg: #e2f6ee;
    --success-text: #116843;
    --warning: #da8b1f;
    --warning-bg: #fdf0dc;
    --warning-text: #8a5810;
    --danger: #d64545;
    --danger-bg: #fbe6e6;
    --danger-text: #99281f;
    --info: #2f7fd1;
    --info-bg: #e5f0fc;
    --info-text: #1b527f;
    --neutral-bg: #eef0f5;
    --neutral-text: #454c63;

    /* ---- Metrics ------------------------------------------------------ */
    --sb-w: 264px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-card: 0 1px 2px rgba(15, 20, 45, 0.04), 0 8px 24px rgba(15, 20, 45, 0.05);
    --shadow-pop: 0 20px 45px rgba(12, 16, 36, 0.18);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: var(--canvas);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: 'Manrope', 'Inter', sans-serif;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
}

a { color: inherit; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ==========================================================================
   Shell layout — fixed sidebar, sticky topbar, independently scrolling main
   ========================================================================== */

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sb-w);
    height: 100vh;
    background: linear-gradient(190deg, var(--ink-900) 0%, var(--ink-700) 100%);
    color: var(--on-dark);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform 0.25s ease;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 6px 16px 20px;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 6px; }

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px 20px;
}
.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #6f8bf5);
    display: grid;
    place-items: center;
    color: white;
    font-family: 'Manrope', sans-serif;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(52, 84, 209, 0.45);
}
.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}
.brand-text strong {
    font-family: 'Manrope', sans-serif;
    font-weight: 800;
    font-size: 15px;
    color: var(--on-dark-strong);
    letter-spacing: 0.01em;
}
.brand-text span {
    font-size: 11px;
    color: var(--muted-soft);
    font-weight: 600;
    letter-spacing: 0.04em;
}

.nav-caption {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.09em;
    color: rgba(203, 209, 232, 0.42);
    padding: 18px 12px 8px;
}

.nav-group { display: grid; gap: 3px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--on-dark);
    text-decoration: none;
    font-weight: 600;
    font-size: 13.5px;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: var(--on-dark-strong); }
.nav-link.active {
    background: rgba(52, 84, 209, 0.28);
    color: var(--on-dark-strong);
}
.nav-link.active svg { opacity: 1; }
.nav-link.active::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    border-radius: 0 4px 4px 0;
    background: var(--gold);
}
.nav-link .nav-pill {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 10.5px;
    font-weight: 800;
    padding: 1px 7px;
    border-radius: 999px;
}

.sidebar-foot {
    padding: 14px 20px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user .avatar {
    width: 34px; height: 34px; border-radius: 10px;
    background: rgba(255,255,255,0.08);
    display: grid; place-items: center;
    font-weight: 800; font-size: 13px; color: var(--on-dark-strong);
    text-transform: uppercase;
}
.sidebar-user .who { line-height: 1.2; overflow: hidden; }
.sidebar-user .who strong { display: block; font-size: 12.5px; color: var(--on-dark-strong); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who span { font-size: 11px; color: var(--muted-soft); }
.sidebar-logout {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin-top: 12px; width: 100%;
    padding: 9px; border-radius: 10px;
    background: rgba(214, 69, 69, 0.16);
    color: #ffb3ac;
    font-size: 12.5px; font-weight: 700;
    text-decoration: none;
    border: 1px solid rgba(214, 69, 69, 0.25);
}
.sidebar-logout:hover { background: rgba(214, 69, 69, 0.26); }
.sidebar-logout svg { width: 15px; height: 15px; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(12, 16, 36, 0.5);
    z-index: 35;
}

/* Main column ------------------------------------------------------------ */

.main-wrap {
    margin-left: var(--sb-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(238, 241, 248, 0.86);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.menu-toggle {
    display: none;
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.menu-toggle svg { width: 19px; height: 19px; }

.page-title { font-size: 1.32rem; font-weight: 800; letter-spacing: -0.015em; }
.page-eyebrow { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }

.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.welcome-chip {
    font-size: 13px; color: var(--muted);
    display: flex; align-items: center; gap: 8px;
}
.welcome-chip strong { color: var(--text); }
.welcome-chip .dot {
    width: 30px; height: 30px; border-radius: 9px;
    background: var(--primary-light); color: var(--primary-dark);
    display: grid; place-items: center; font-weight: 800; font-size: 12px;
}

.content {
    flex: 1;
    padding: 28px 32px 48px;
    max-width: 1400px;
    width: 100%;
}
.content.narrow { max-width: 900px; }
.content.wide { max-width: 1500px; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    font-size: 13.5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-weight: 700;
    font-family: inherit;
    line-height: 1;
    transition: filter 0.15s ease, transform 0.1s ease, background 0.15s ease;
    white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 6px 14px rgba(52, 84, 209, 0.28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { filter: brightness(0.92); }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { filter: brightness(0.92); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e9ecf5; }
.btn-ghost-danger { background: var(--danger-bg); color: var(--danger-text); }
.btn-ghost-danger:hover { filter: brightness(0.96); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}
.card-header {
    padding: 16px 22px;
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
    font-size: 14.5px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.card-header .subtle { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.card-header-dark {
    background: linear-gradient(120deg, var(--ink-900), var(--ink-700));
    color: white;
    border-bottom: none;
}
.card-body { padding: 22px; }
.card-body.pad-sm { padding: 14px 18px; }

.count-chip {
    background: var(--neutral-bg);
    color: var(--neutral-text);
    border-radius: 999px;
    padding: 3px 11px;
    font-size: 11.5px;
    font-weight: 800;
}
.count-chip.danger { background: var(--danger-bg); color: var(--danger-text); }
.count-chip.warning { background: var(--warning-bg); color: var(--warning-text); }
.count-chip.success { background: var(--success-bg); color: var(--success-text); }

/* Page header banner -------------------------------------------------- */
.page-header {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    padding: 20px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.page-header h2 { font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.page-header h2 svg { width: 20px; height: 20px; color: var(--primary); }
.page-header p { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ==========================================================================
   Stat cards
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-top: 3px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 20px 20px 18px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    box-shadow: var(--shadow-card);
}
.stat-card.tone-green { border-top-color: var(--success); }
.stat-card.tone-red { border-top-color: var(--danger); }
.stat-card.tone-gold { border-top-color: var(--gold); }
.stat-card.tone-info { border-top-color: var(--info); }

.stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center; flex-shrink: 0;
}
.stat-icon svg { width: 21px; height: 21px; }
.stat-icon.blue { background: var(--primary-light); color: var(--primary-dark); }
.stat-icon.green { background: var(--success-bg); color: var(--success-text); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger-text); }
.stat-icon.gold { background: var(--gold-light); color: var(--gold); }
.stat-icon.info { background: var(--info-bg); color: var(--info-text); }

.stat-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.stat-value { font-family: 'Manrope', sans-serif; font-size: 1.55rem; font-weight: 800; margin-top: 3px; letter-spacing: -0.02em; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* Centered report-style stat card */
.stat-card.centered { flex-direction: column; align-items: center; text-align: center; border-top-width: 3px; }
.stat-card.centered .stat-label { margin-bottom: 8px; }
.stat-card.centered .stat-value { font-size: 1.7rem; }

/* ==========================================================================
   Quick action tiles
   ========================================================================== */

.menu-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.menu-btn {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 20px 16px;
    text-decoration: none;
    color: var(--text);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.menu-btn:hover { transform: translateY(-3px); border-color: var(--primary); }
.menu-btn .menu-icon {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--primary-light); color: var(--primary-dark);
    display: grid; place-items: center;
}
.menu-btn .menu-icon svg { width: 18px; height: 18px; }
.menu-btn .title { font-weight: 800; font-size: 13.5px; }
.menu-btn .subtitle { color: var(--muted); font-size: 12px; }
.menu-btn .badge {
    align-self: flex-start;
    background: var(--danger); color: white;
    padding: 2px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 800;
}

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.chart-wrap { padding: 18px; min-height: 270px; }
.content-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    padding: 12px 16px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text);
    font-size: 13.2px;
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.cell-name { font-weight: 700; }
.cell-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.cell-amount { font-family: 'Manrope', sans-serif; font-weight: 700; }
.cell-amount.up { color: var(--success-text); }
.cell-amount.down { color: var(--danger-text); }
.cell-amount.pending { color: var(--warning-text); }
.no-data { text-align: center; color: var(--muted); padding: 46px 20px; font-size: 13.5px; }
.no-data a { color: var(--primary); font-weight: 700; text-decoration: none; }

.license-key {
    font-family: 'SF Mono', 'Courier New', monospace;
    background: var(--gold-light);
    color: #6b4c17;
    padding: 4px 9px;
    border-radius: 7px;
    font-size: 11px;
    letter-spacing: 0.02em;
    display: inline-block;
}
.no-license { color: var(--danger-text); font-weight: 700; font-size: 12px; }

.action-links { display: flex; gap: 6px; flex-wrap: wrap; }

.thumb {
    width: 58px; height: 44px; object-fit: cover; border-radius: 8px;
    cursor: pointer; border: 1px solid var(--border);
}
.thumb-sq { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; cursor: pointer; border: 1px solid var(--border); }

/* ==========================================================================
   Badges
   ========================================================================== */

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-gold { background: var(--gold-light); color: #6b4c17; }

/* ==========================================================================
   Alerts
   ========================================================================== */

.alert { padding: 13px 18px; border-radius: var(--radius-md); margin-bottom: 18px; font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 10px; border: 1px solid transparent; }
.alert svg { width: 17px; height: 17px; flex-shrink: 0; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: #c3ecda; }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); border-color: #f4c9c9; }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: #f4dfb4; }
.alert-info { background: var(--info-bg); color: var(--info-text); border-color: #c6dff5; }

.info-box, .warning-box {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 18px;
    font-size: 12.8px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.info-box { background: var(--info-bg); color: var(--info-text); border-left: 3px solid var(--info); }
.warning-box { background: var(--warning-bg); color: var(--warning-text); border-left: 3px solid var(--warning); }
.info-box svg, .warning-box svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-card { background: var(--surface); border: 1px solid var(--border-soft); padding: 26px; border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin-bottom: 20px; }
.form-section { margin-bottom: 26px; padding-bottom: 22px; border-bottom: 1px solid var(--border-soft); }
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section h3 { font-size: 14.5px; font-weight: 800; margin-bottom: 18px; display: flex; align-items: center; gap: 9px; }
.form-section h3 svg { width: 17px; height: 17px; color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 7px; font-weight: 700; color: var(--text); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13.5px; background: var(--surface); color: var(--text); font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light);
}
.form-group small { display: block; margin-top: 6px; color: var(--muted); font-size: 11.8px; }
.btn-group { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

.search-box { background: var(--surface); border: 1px solid var(--border-soft); padding: 16px; border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin-bottom: 20px; }
.search-box form { display: flex; gap: 10px; width: 100%; flex-wrap: wrap; align-items: center; }
.search-box input, .search-box select { padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13.5px; background: var(--surface-alt); }
.search-box input { flex: 1; min-width: 220px; }
.search-field { position: relative; flex: 1; min-width: 220px; }
.search-field svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted-soft); }
.search-field input { padding-left: 36px; width: 100%; }

.filter-box { background: var(--surface); border: 1px solid var(--border-soft); padding: 18px; border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin-bottom: 20px; }
.filter-box form { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.filter-box input { padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13.5px; }
.filter-box label { font-size: 12.8px; font-weight: 700; color: var(--muted); }

/* License / key display */
.license-display {
    background: var(--gold-light); padding: 15px 16px; border-radius: var(--radius-md); margin-bottom: 12px;
    font-family: 'SF Mono', 'Courier New', monospace; font-size: 13px; color: #6b4c17; word-break: break-all;
    border: 1px dashed #e3c583;
}
.toggle-license { cursor: pointer; color: var(--primary); font-weight: 700; font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; }
#license-edit-section { display: none; margin-top: 14px; }

.license-box {
    background: linear-gradient(135deg, var(--gold-light), #fff7ea);
    border: 1px dashed #e3c583;
    border-radius: var(--radius-md);
    padding: 18px;
    color: #6b4c17;
    font-weight: 800;
    font-size: 0.98rem;
    word-break: break-all;
    text-align: center;
    letter-spacing: 0.04em;
    font-family: 'SF Mono', 'Courier New', monospace;
}

/* ==========================================================================
   Detail page grid / info rows
   ========================================================================== */

.detail-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(440px, 1.6fr); gap: 20px; }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); font-size: 13.3px; }
.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--muted); }
.info-row .value { font-weight: 700; text-align: right; }

.history-list { display: grid; gap: 10px; }
.history-item { background: var(--surface-alt); border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 11px 13px; font-size: 12.6px; }
.history-item strong { font-size: 13px; }
.history-item small { color: var(--muted); }

/* ==========================================================================
   Progress bars
   ========================================================================== */

.progress-bar { background: var(--border); border-radius: 999px; height: 9px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 999px; }
.progress-fill.green { background: var(--success); }
.progress-fill.orange { background: var(--warning); }
.progress-fill.red { background: var(--danger); }

/* ==========================================================================
   Modal (image preview)
   ========================================================================== */

.modal { position: fixed; inset: 0; display: none; place-items: center; background: rgba(12, 16, 36, 0.75); z-index: 100; padding: 24px; }
.modal-inner { position: relative; max-width: 90vw; max-height: 90vh; background: white; border-radius: 14px; padding: 10px; }
.modal-inner img { display: block; max-width: 86vw; max-height: 82vh; border-radius: 8px; }
.close-btn { position: absolute; top: -14px; right: -14px; width: 32px; height: 32px; border-radius: 50%; background: white; border: 1px solid var(--border); font-size: 1.3rem; cursor: pointer; box-shadow: var(--shadow-pop); line-height: 1; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1180px) {
    .stats-grid, .menu-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-pop); }
    .app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .app-shell.sidebar-open .sidebar-backdrop { display: block; }
    .main-wrap { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .content { padding: 20px 18px 40px; }
    .topbar { padding: 14px 18px; }
    .chart-grid, .content-row { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .welcome-chip span.username-text { display: none; }
}

@media (max-width: 640px) {
    .stats-grid, .menu-row { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
}

/* ==========================================================================
   Shared page components (client profile, verifications, license)
   ========================================================================== */

.ts-hero {
    position: relative; overflow: hidden;
    border-radius: 20px; padding: 26px 28px; margin-bottom: 22px;
    background: linear-gradient(120deg, #312e81 0%, #4f46e5 45%, #7c3aed 100%);
    color: #fff; box-shadow: 0 18px 40px rgba(79, 70, 229, 0.28);
    display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.ts-hero::before, .ts-hero::after { content: ''; position: absolute; border-radius: 50%; background: rgba(255,255,255,0.08); pointer-events: none; }
.ts-hero::before { width: 260px; height: 260px; right: -60px; top: -120px; }
.ts-hero::after { width: 160px; height: 160px; right: 200px; bottom: -100px; }
.ts-hero > * { position: relative; z-index: 1; }
.ts-hero.tone-green { background: linear-gradient(120deg, #064e3b 0%, #059669 50%, #10b981 100%); box-shadow: 0 18px 40px rgba(5, 150, 105, 0.25); }
.ts-hero h1 { color: #fff; font-size: 1.5rem; font-weight: 800; }
.ts-hero p { margin: 6px 0 0; color: rgba(255,255,255,0.8); font-size: 13.5px; }
.ts-hero-id { display: flex; align-items: center; gap: 16px; min-width: 0; }
.ts-hero-avatar {
    width: 62px; height: 62px; border-radius: 18px; flex-shrink: 0;
    display: grid; place-items: center; font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 1.3rem;
    background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.25); color: #fff;
}
.ts-hero-meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: rgba(255,255,255,0.82); }
.ts-hero-meta span { display: inline-flex; align-items: center; gap: 5px; }
.ts-hero-meta svg { width: 13px; height: 13px; }
.ts-hero-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.ts-hero-stat { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); border-radius: 14px; padding: 12px 18px; min-width: 130px; }
.ts-hero-stat span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,0.72); font-weight: 700; }
.ts-hero-stat strong { font-family: 'Manrope', sans-serif; font-size: 1.3rem; font-weight: 800; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-green { background: #d1fae5; color: #047857; }
.pill-amber { background: #fef3c7; color: #b45309; }
.pill-red { background: #ffe4e6; color: #be123c; }
.pill-slate { background: #e2e8f0; color: #475569; }
.pill-blue { background: #e0e7ff; color: #4338ca; }
.pill-light { background: rgba(255,255,255,0.18); color: #fff; }

.ts-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.ts-kpis.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ts-kpi {
    --c1: #6366f1; --c2: #8b5cf6;
    position: relative; overflow: hidden; display: flex; align-items: center; gap: 14px;
    background: #fff; border: 1px solid var(--border-soft); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow-card);
}
.ts-kpi::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--c1), var(--c2)); }
.ts-kpi .ico { width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--c1), var(--c2)); box-shadow: 0 8px 18px -6px var(--c1); }
.ts-kpi .ico svg { width: 19px; height: 19px; }
.ts-kpi .lbl { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.ts-kpi .num { font-family: 'Manrope', sans-serif; font-size: 1.3rem; font-weight: 800; line-height: 1.2; }
.ts-kpi .sub { font-size: 11.5px; color: var(--muted); }
.k-indigo { --c1: #6366f1; --c2: #8b5cf6; }
.k-green { --c1: #10b981; --c2: #34d399; }
.k-amber { --c1: #f59e0b; --c2: #fbbf24; }
.k-red { --c1: #f43f5e; --c2: #fb7185; }
.k-sky { --c1: #0ea5e9; --c2: #22d3ee; }

.ts-card { background: #fff; border: 1px solid var(--border-soft); border-radius: 18px; box-shadow: var(--shadow-card); overflow: hidden; margin-bottom: 20px; }
.ts-card-head { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ts-card-head h3 { font-size: 14.5px; font-weight: 800; display: flex; align-items: center; gap: 9px; }
.ts-card-head h3 svg { width: 17px; height: 17px; color: #6366f1; }
.ts-card-head .subtle { color: var(--muted); font-size: 12px; font-weight: 600; }
.ts-card-body { padding: 18px 20px; }

.ts-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.ts-table th { background: linear-gradient(180deg, #f8f9ff, #f3f5fc); padding: 12px 14px; font-size: 10.8px; letter-spacing: .07em; color: #6b7290; }
.ts-table td { padding: 13px 14px; font-size: 13px; }
.ts-table tbody tr:hover { background: #fafbff; }
.ts-table .muted { color: var(--muted); font-size: 11.8px; }

.delay { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.delay svg { width: 13px; height: 13px; }
.delay-on_time { color: #047857; }
.delay-late { color: #b45309; }
.delay-running { color: #be123c; }
.delay-upcoming { color: var(--muted); }

.ts-dl .row { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.ts-dl .row:last-child { border-bottom: none; }
.ts-dl .row span:first-child { color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.ts-dl .row span:first-child svg { width: 14px; height: 14px; color: var(--muted-soft); }
.ts-dl .row span:last-child { font-weight: 700; text-align: right; word-break: break-word; }

.ts-key { display: flex; align-items: center; gap: 8px; }
.ts-key code {
    flex: 1; min-width: 0; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12.5px;
    background: #f5f3ff; color: #5b21b6; border: 1px dashed #c4b5fd; padding: 10px 12px; border-radius: 10px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ts-copy {
    width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: #fff; color: var(--muted);
    cursor: pointer; display: grid; place-items: center; flex-shrink: 0; transition: all .15s ease;
}
.ts-copy:hover { color: #6366f1; border-color: #c7d2fe; background: #eef2ff; }
.ts-copy.copied { color: #059669; border-color: #a7f3d0; background: #ecfdf5; }
.ts-copy svg { width: 15px; height: 15px; }

/* Timeline */
.ts-timeline { position: relative; padding-left: 26px; max-height: 460px; overflow-y: auto; }
.ts-timeline::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.ts-tl-item { position: relative; padding: 0 0 16px; }
.ts-tl-item:last-child { padding-bottom: 0; }
.ts-tl-dot { position: absolute; left: -26px; top: 2px; width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--border); background: #94a3b8; }
.ts-tl-item.t-created .ts-tl-dot { background: #6366f1; }
.ts-tl-item.t-license .ts-tl-dot { background: #8b5cf6; }
.ts-tl-item.t-invoice .ts-tl-dot { background: #0ea5e9; }
.ts-tl-item.t-upload .ts-tl-dot { background: #f59e0b; }
.ts-tl-item.t-verified .ts-tl-dot { background: #10b981; }
.ts-tl-title { font-weight: 700; font-size: 13px; }
.ts-tl-detail { color: var(--muted); font-size: 12px; word-break: break-word; }
.ts-tl-time { color: var(--muted-soft); font-size: 11.5px; margin-top: 2px; }

/* Dropdown */
.ts-dropdown { position: relative; }
.ts-dropdown-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 280px;
    background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 6px;
}
.ts-dropdown.open .ts-dropdown-menu { display: block; }
.ts-dropdown-menu a { display: flex; gap: 11px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text); }
.ts-dropdown-menu a:hover { background: #f5f6ff; }
.ts-dropdown-menu .di { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.ts-dropdown-menu .di svg { width: 16px; height: 16px; }
.ts-dropdown-menu strong { display: block; font-size: 13px; }
.ts-dropdown-menu small { color: var(--muted); font-size: 11.5px; }

/* Proof thumbnails */
.ts-proof { width: 56px; height: 44px; border-radius: 9px; object-fit: cover; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.ts-proof-file { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: #4338ca; text-decoration: none; }
.ts-proof-file svg { width: 14px; height: 14px; }

.ts-empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.ts-empty .ico { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, #eef2ff, #f5f3ff); color: #6366f1; }
.ts-empty .ico svg { width: 26px; height: 26px; }
.ts-empty h3 { font-size: 0.98rem; margin-bottom: 4px; }
.ts-empty p { margin: 0; font-size: 13px; }

.ts-two { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(0, 2fr); gap: 20px; align-items: start; }

@media (max-width: 1180px) {
    .ts-kpis, .ts-kpis.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ts-two { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .ts-kpis, .ts-kpis.cols-4 { grid-template-columns: 1fr; }
    .ts-hero { padding: 20px; }
    .ts-hero-stat { flex: 1; min-width: 0; }
}
