/* ============================================================
   DESIGN SYSTEM - Modern SaaS Dashboard
   Inspired by: Linear, Vercel, Stripe, GitHub
   ============================================================ */

:root {
    /* Colors - Surface */
    --bg-base: #0a0a0b;
    --bg-surface: #111114;
    --bg-elevated: #16171b;
    --bg-hover: #1c1d22;
    --bg-active: #22232a;
    
    /* Colors - Border */
    --border-subtle: #1f2024;
    --border-default: #26272d;
    --border-strong: #34353d;
    
    /* Colors - Text */
    --text-primary: #ededef;
    --text-secondary: #9ea0aa;
    --text-tertiary: #6e7079;
    --text-disabled: #4d4f56;
    
    /* Colors - Brand (Indigo/Violet) */
    --brand-50:  #f5f3ff;
    --brand-200: #c7d2fe;
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    
    /* Colors - Semantic */
    --success: #10b981;
    --success-soft: rgba(16, 185, 129, .12);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, .12);
    --danger:  #ef4444;
    --danger-soft:  rgba(239, 68, 68, .12);
    --info:    #06b6d4;
    --info-soft: rgba(6, 182, 212, .12);
    
    /* Spacing (8pt grid) */
    --space-1:  4px;
    --space-2:  8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    
    /* Radius */
    --radius-sm:  4px;
    --radius-md:  6px;
    --radius-lg:  8px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 2px 8px rgba(0,0,0,.25);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.32);
    
    /* Transitions */
    --t-fast: 120ms ease;
    --t-base: 180ms ease;
    
    /* Layout */
    --sidebar-w: 248px;
    --header-h: 56px;
    --content-max: 1280px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
ul, ol { list-style: none; }
a { color: var(--brand-400); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--brand-500); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

.sidebar-brand {
    height: var(--header-h);
    padding: 0 var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}
.brand-logo {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--brand-500), #a855f7);
    color: #fff;
    font-size: 14px; font-weight: 700;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}
.brand-info { min-width: 0; flex: 1; }
.brand-name {
    font-size: 13px; font-weight: 600; color: var(--text-primary);
    line-height: 1.2;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand-tag {
    font-size: 11px; color: var(--text-tertiary);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
}
.nav-section {
    margin-bottom: var(--space-5);
}
.nav-label {
    padding: 0 var(--space-3) var(--space-2);
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.nav-link {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    transition: background var(--t-fast), color var(--t-fast);
    margin-bottom: 2px;
}
.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}
.nav-link.active {
    background: var(--bg-active);
    color: var(--text-primary);
    box-shadow: inset 2px 0 0 var(--brand-500);
}
.nav-link.active .nav-icon { color: var(--brand-400); }
.nav-icon {
    width: 16px; height: 16px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-tertiary);
    transition: color var(--t-fast);
    flex-shrink: 0;
}
.nav-link:hover .nav-icon { color: var(--text-secondary); }

.sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   TOPBAR / HEADER
   ============================================================ */
.top-header {
    height: var(--header-h);
    padding: 0 var(--space-6);
    background: rgba(17, 17, 20, .85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
.menu-toggle {
    display: none;
    width: 32px; height: 32px;
    align-items: center; justify-content: center;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
}
.menu-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.search-box {
    flex: 1;
    max-width: 360px;
    position: relative;
}
.search-box input {
    width: 100%;
    height: 32px;
    padding: 0 var(--space-3) 0 32px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13px;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.search-box input:focus {
    outline: none;
    border-color: var(--brand-500);
    background: var(--bg-active);
}
.search-box input::placeholder { color: var(--text-tertiary); }
.search-box::before {
    content: '';
    position: absolute;
    left: 10px; top: 50%;
    width: 14px; height: 14px;
    transform: translateY(-50%);
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e7079' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.35-4.35'/></svg>") center/contain no-repeat;
    pointer-events: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
    min-width: 0;
}
.header-action {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: background var(--t-fast), color var(--t-fast);
    position: relative;
}
.header-action:hover { background: var(--bg-hover); color: var(--text-primary); }
.header-action .dot {
    position: absolute;
    top: 7px; right: 7px;
    width: 7px; height: 7px;
    background: var(--brand-500);
    border: 2px solid var(--bg-surface);
    border-radius: 50%;
}
.header-license-badge {
    height: 28px;
    padding: 0 12px;
    text-decoration: none;
}
.header-logout { text-decoration: none; }

.user-menu {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 4px 6px 4px 4px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: all var(--t-fast);
}
.user-menu:hover {
    background: var(--bg-hover);
    border-color: var(--border-subtle);
}
.user-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-500), #a855f7);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}
.user-name-label {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
}

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
    padding: var(--space-8);
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}
.page-header {
    margin-bottom: var(--space-8);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--space-4);
    flex-wrap: wrap;
}
.page-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    letter-spacing: -0.01em;
}
.page-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: var(--space-1);
}

/* ============================================================
   CARD
   ============================================================ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    min-width: 0;
    transition: border-color var(--t-base);
}
.card:hover { border-color: var(--border-default); }

.section { padding: var(--space-6); margin-bottom: var(--space-5); }
.section-title {
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    margin-bottom: var(--space-4);
    letter-spacing: -0.005em;
    line-height: 1.4;
}
.section-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: -8px;
    margin-bottom: var(--space-4);
}

.text-muted { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.mono {
    font-family: var(--font-mono);
    color: var(--brand-400);
    font-size: 12px;
    overflow-wrap: anywhere;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
    gap: var(--space-5);
    align-items: start;
}

.settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, .75fr);
    gap: var(--space-5);
    align-items: start;
}

.quick-action-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.stat-box {
    padding: var(--space-5);
    position: relative;
    overflow: hidden;
    transition: all var(--t-base);
}
.stat-box:hover {
    border-color: var(--border-default);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.stat-box-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: var(--space-4);
}
.stat-label {
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.stat-icon {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    flex-shrink: 0;
}
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-soft);  color: var(--danger); }
.stat-icon.info    { background: var(--info-soft);    color: var(--info); }
.stat-icon.brand   { background: rgba(99,102,241,.12); color: var(--brand-400); }

.stat-value {
    color: var(--text-primary);
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.02em;
}
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger  { color: var(--danger); }
.stat-value.info    { color: var(--info); }
.stat-unit {
    font-size: 14px;
    color: var(--text-tertiary);
    font-weight: 500;
}
.stat-contact {
    font-size: 16px;
    overflow-wrap: anywhere;
}
.stat-trend {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: var(--space-2);
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: var(--space-2);
    height: 32px;
    padding: 0 var(--space-3);
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
    transition: all var(--t-fast);
    white-space: nowrap;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
}
.btn-primary:hover {
    background: var(--brand-700);
    border-color: var(--brand-700);
    color: #fff;
}
.btn-secondary { background: var(--bg-elevated); }
.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-subtle); }
.btn-lg { height: 40px; padding: 0 var(--space-4); font-size: 14px; }
.btn-sm { height: 28px; padding: 0 var(--space-3); font-size: 12px; }

/* ============================================================
   BADGE
   ============================================================ */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    height: 22px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 11px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: rgba(16,185,129,.25); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(245,158,11,.25); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239,68,68,.25); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: rgba(6,182,212,.25); }
.badge-brand   { background: rgba(99,102,241,.12); color: var(--brand-400); border-color: rgba(99,102,241,.25); }
.badge-dot::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ============================================================
   TABLE
   ============================================================ */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-card .data-table { min-width: 720px; }
.table-card .license-history-table { min-width: 560px; }
.table-card-header {
    padding: var(--space-5) var(--space-6) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}
.table-card-header .section-title { margin: 0; }
.data-table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-base);
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border-subtle);
}
.data-table th:first-child { border-top-left-radius: var(--radius-xl); }
.data-table th:last-child  { border-top-right-radius: var(--radius-xl); }
.data-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: var(--bg-hover); }
.table-muted { color: var(--text-tertiary); }
.table-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: var(--space-10);
}
.key-cell,
.mid-cell {
    display: inline-block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    white-space: nowrap;
}
.machine-input {
    font-family: var(--font-mono);
    font-size: 12px;
}
.current-machine-card {
    background: var(--bg-elevated);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 14px;
}
.current-machine-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 4px;
}
.current-machine-value {
    font-size: 11px;
    word-break: break-all;
}

/* ============================================================
   FORM
   ============================================================ */
.form-row { margin-bottom: var(--space-4); }
.form-label {
    display: block;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.form-control {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color var(--t-fast);
}
.form-control:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-control::placeholder { color: var(--text-tertiary); }
textarea.form-control { height: auto; padding: var(--space-3); resize: vertical; min-height: 80px; }
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ea0aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    padding-right: 32px;
}
.form-hint {
    display: block;
    color: var(--text-tertiary);
    font-size: 12px;
    margin-top: 6px;
    line-height: 1.5;
}

/* ============================================================
   ALERT
   ============================================================ */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    margin-bottom: var(--space-5);
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    line-height: 1.5;
}
.icon-shrink { flex-shrink: 0; }
.icon-top {
    flex-shrink: 0;
    margin-top: 2px;
}
.alert a { font-weight: 500; }
.alert-success { background: var(--success-soft); border-color: rgba(16,185,129,.3); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: rgba(245,158,11,.3); color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: rgba(239,68,68,.3);  color: var(--danger); }
.alert-info    { background: var(--info-soft);    border-color: rgba(6,182,212,.3);  color: var(--info); }

/* ============================================================
   LICENSE CARD
   ============================================================ */
.license-card { padding: var(--space-6); margin-bottom: var(--space-5); }
.license-top {
    display: flex; justify-content: space-between; align-items: flex-start;
    flex-wrap: wrap; gap: var(--space-4);
}
.license-label {
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: var(--space-2);
}
.license-key {
    font-family: var(--font-mono);
    font-size: 22px;
    color: var(--brand-400);
    letter-spacing: 1px;
    font-weight: 600;
}
.license-badges {
    margin-top: var(--space-3);
    display: flex; gap: var(--space-2); flex-wrap: wrap;
}
.license-progress { margin-top: var(--space-6); }
.license-progress-info {
    display: flex; justify-content: space-between;
    font-size: 12px; color: var(--text-secondary);
    margin-bottom: var(--space-2);
}
.license-progress-info b { color: var(--text-primary); font-weight: 600; }
.progress-bar {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--brand-500));
    transition: width .4s ease;
}

/* ============================================================
   WORKFLOW / TIMELINE
   ============================================================ */
.workflow {
    list-style: none;
    padding: 0;
    margin: 0;
}
.workflow-step {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    position: relative;
}
.workflow-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 15px; top: 44px; bottom: -8px;
    width: 2px;
    background: var(--border-subtle);
}
.workflow-step.done::before { background: var(--success); }
.workflow-num {
    flex-shrink: 0;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    z-index: 1;
}
.workflow-step.done .workflow-num {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}
.workflow-step.active .workflow-num {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(99,102,241,.15);
}
.workflow-content { flex: 1; padding-top: 4px; }
.workflow-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.workflow-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}
.workflow-desc b { color: var(--text-primary); font-weight: 600; }

/* Quick Action Cards */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-4);
}
.quick-action {
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    transition: all var(--t-base);
}
.quick-action:hover {
    border-color: var(--brand-500);
    background: var(--bg-hover);
    transform: translateY(-1px);
    text-decoration: none;
}
.quick-action-icon {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-active);
    border-radius: var(--radius-md);
    color: var(--brand-400);
    flex-shrink: 0;
}
.quick-action-text {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}
.quick-action-desc {
    color: var(--text-tertiary);
    font-size: 12px;
    margin-top: 2px;
}

/* ============================================================
   ADMIN TABS
   ============================================================ */
.admin-tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
}
.admin-tabs .tab {
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 10px 14px;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    font-size: 13px;
    font-weight: 500;
    transition: color var(--t-fast), border-color var(--t-fast);
    white-space: nowrap;
    margin-bottom: -1px;
}
.admin-tabs .tab:hover { color: var(--text-primary); text-decoration: none; }
.admin-tabs .tab.active {
    color: var(--brand-400);
    border-bottom-color: var(--brand-500);
}

.search-bar {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    align-items: center;
}
.renew-note { margin-bottom: 6px; }
.renew-price { color: var(--brand-400); }
.contact-line {
    color: var(--text-secondary);
    font-size: 13px;
}
.search-bar input.form-control { flex: 1; max-width: 480px; }

.admin-account-note { margin-bottom: 14px; }
.settings-divider {
    border-top: 1px solid var(--border-default);
    margin: 18px 0;
    padding-top: 16px;
}
.required-mark { color: var(--danger); }
.auth-bg-preview-row {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    flex-wrap: wrap;
}
.auth-bg-thumb {
    width: 120px;
    height: 70px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    flex-shrink: 0;
}
.auth-bg-path {
    color: var(--text-secondary);
    flex: 1 1 220px;
    min-width: 0;
}
.checkbox-row {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 13px;
}
.optional-label {
    color: var(--text-tertiary);
    text-transform: none;
}

/* Mini buttons in tables */
.actions-row {
    display: flex; gap: 4px; flex-wrap: wrap;
}
.btn-mini {
    height: 24px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    transition: all var(--t-fast);
    white-space: nowrap;
}
.btn-mini:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-default); }
.btn-mini.primary { color: var(--brand-400); border-color: rgba(99,102,241,.4); }
.btn-mini.primary:hover { background: rgba(99,102,241,.12); }
.btn-mini.success { color: var(--success); border-color: rgba(16,185,129,.4); }
.btn-mini.success:hover { background: var(--success-soft); }
.btn-mini.danger  { color: var(--danger); border-color: rgba(239,68,68,.4); }
.btn-mini.danger:hover  { background: var(--danger-soft); }
.inline { display: inline; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-bg {
    position: fixed;
    inset: 0; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: var(--space-5);
}
.modal-bg.show { display: flex !important; }
.modal-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-box h3 {
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    font-size: 16px;
    font-weight: 600;
}
.modal-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-shell {
    --auth-bg-image: none;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    overflow-y: auto;
    background-color: var(--bg-base);
    background-image:
        var(--auth-bg-image),
        radial-gradient(circle at 20% 0%, rgba(99,102,241,.08), transparent 60%),
        radial-gradient(circle at 80% 100%, rgba(168,85,247,.08), transparent 60%);
    background-size: cover, auto, auto;
    background-position: center, 20% 0%, 80% 100%;
    background-repeat: no-repeat;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    margin: auto 0;
    background: rgba(17, 17, 20, .92);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: var(--radius-2xl);
    padding: var(--space-8);
    box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.auth-brand {
    display: flex; align-items: center; gap: var(--space-3);
    margin-bottom: var(--space-6);
}
.auth-brand .brand-logo { width: 36px; height: 36px; font-size: 16px; }
.auth-brand .brand-name {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 600;
}
.auth-brand .brand-tag {
    font-size: 11px;
    color: var(--text-tertiary);
}
.auth-card .btn-lg { width: 100%; }
.auth-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
    margin-bottom: var(--space-6);
}
.auth-links {
    text-align: center;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 13px;
}
.trial-note {
    display: flex; gap: var(--space-3);
    background: rgba(99,102,241,.08);
    border: 1px solid rgba(99,102,241,.2);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    color: var(--brand-400);
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: var(--space-4);
}

/* ============================================================
   RESPONSIVE - Mobile / Tablet / Desktop
   ============================================================ */

/* TABLET (≤ 1024px) */
@media (max-width: 1024px) {
    :root {
        --sidebar-w: 220px;
    }
    .page-content { padding: var(--space-6); }
    .page-title { font-size: 20px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid,
    .settings-grid { grid-template-columns: 1fr; }
}

/* MOBILE (≤ 768px) */
@media (max-width: 768px) {
    :root {
        --sidebar-w: 260px;
        --header-h: 52px;
    }
    
    /* Sidebar drawer */
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: var(--sidebar-w);
        z-index: 200;
        transition: left .25s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,.4);
    }
    body.sidebar-open .sidebar { left: 0; }
    
    /* Backdrop khi mở sidebar */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        backdrop-filter: blur(2px);
        z-index: 150;
    }
    
    .menu-toggle { display: flex; }
    
    /* Header */
    .top-header {
        padding: 0 var(--space-4);
        gap: var(--space-2);
    }
    .search-box { display: none; }
    .header-right { gap: var(--space-1); }
    .user-info-pill { padding: 4px 8px 4px 4px; }
    .user-info-pill .user-name-label { display: none; }
    
    /* Page */
    .page-content { padding: var(--space-5) var(--space-4); }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        margin-bottom: var(--space-5);
    }
    .page-header > .btn { width: 100%; justify-content: center; }
    .page-title { font-size: 19px; }
    .page-subtitle { font-size: 13px; }
    
    /* Stats - 1 column */
    .stat-grid { grid-template-columns: 1fr; gap: var(--space-3); }
    .stat-box { padding: var(--space-4); }
    .stat-value { font-size: 22px; }
    
    /* Section */
    .section { padding: var(--space-5) var(--space-4); margin-bottom: var(--space-4); }
    .section-title { font-size: 14px; }
    
    /* Key card */
    .license-card { padding: var(--space-5) var(--space-4); }
    .license-top { flex-direction: column; align-items: stretch; gap: var(--space-3); }
    .license-key { font-size: 16px; letter-spacing: 0.5px; word-break: break-all; }
    .license-card .btn { width: 100%; justify-content: center; }
    
    /* Workflow */
    .workflow-step { padding: var(--space-3) 0; }
    .workflow-step:not(:last-child)::before { left: 13px; top: 38px; }
    .workflow-num { width: 28px; height: 28px; font-size: 12px; }
    .workflow-title { font-size: 13px; }
    .workflow-desc { font-size: 12px; }
    
    /* Quick action */
    .quick-action { padding: var(--space-3); }
    .quick-action-icon { width: 32px; height: 32px; }
    .quick-action-stack { gap: var(--space-3); }
    
    /* Auth pages */
    .auth-shell { padding: var(--space-4); }
    .auth-card { padding: var(--space-6); border-radius: var(--radius-xl); }
    .auth-title { font-size: 19px; }
    
    /* Form */
    .form-control { font-size: 15px; height: 40px; } /* tránh iOS zoom */
    .btn-lg { height: 44px; font-size: 14px; }
    
    /* Dashboard 2-col → 1-col */
    .dashboard-grid { grid-template-columns: 1fr !important; }
    .settings-grid { grid-template-columns: 1fr; }
    
    /* Admin tables - cuộn ngang */
    .data-table {
        font-size: 12px;
        min-width: 680px;
    }
    .table-card,
    .card[style*="overflow-x"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-card .data-table { min-width: 680px; }
    .table-card .license-history-table { min-width: 560px; }
    .table-card-header { padding: var(--space-4); }
    .license-history-table { min-width: 560px; }
    
    /* Admin tabs scroll */
    .admin-tabs {
        gap: 0;
        margin-left: calc(var(--space-4) * -1);
        margin-right: calc(var(--space-4) * -1);
        padding: 0 var(--space-4);
    }
    .admin-tabs .tab { padding: 10px 12px; font-size: 12px; }
    
    /* Search bar */
    .search-bar { flex-wrap: wrap; }
    .search-bar input.form-control { max-width: 100%; flex: 1 1 100%; }
    .search-bar .btn { flex: 1 1 0; }
    
    /* Modal */
    .modal-bg,
    .ui-modal { padding: var(--space-4); align-items: flex-end; }
    .modal-box,
    .ui-modal-box {
        max-width: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        animation: modalInMobile .25s cubic-bezier(.4, 0, .2, 1);
    }
    .modal-box { max-height: 86vh; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions .btn { width: 100%; }
    .ui-modal-body { padding: var(--space-5) var(--space-4); }
    .ui-modal-footer { padding: var(--space-3) var(--space-4); flex-direction: column-reverse; }
    .ui-modal-footer .btn { width: 100%; }
    
    @keyframes modalInMobile {
        from { transform: translateY(100%); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }
    
    /* Toast */
    .toast-container {
        top: auto;
        bottom: var(--space-4);
        right: var(--space-4);
        left: var(--space-4);
        max-width: none;
    }
    .toast { animation: toastInMobile .25s ease; }
    .toast.removing { animation: toastOutMobile .2s ease forwards; }
    @keyframes toastInMobile {
        from { transform: translateY(120%); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }
    @keyframes toastOutMobile {
        from { transform: translateY(0); opacity: 1; }
        to   { transform: translateY(120%); opacity: 0; }
    }
    
    /* Table mini buttons - wrap dễ hơn */
    .actions-row { gap: 4px; }
    .btn-mini { font-size: 10px; padding: 0 6px; height: 22px; }
}

/* SMALL MOBILE (≤ 480px) */
@media (max-width: 480px) {
    .page-content { padding: var(--space-4) var(--space-3); }
    .page-title { font-size: 18px; }
    .top-header { padding: 0 var(--space-3); }
    .header-action { display: none; }
    .top-header .btn-sm { padding: 0 9px; }
    .auth-card { padding: var(--space-5) var(--space-4); }
    .auth-brand { gap: var(--space-2); margin-bottom: var(--space-4); }
    .stat-icon { width: 28px; height: 28px; }
    .stat-icon svg { width: 12px; height: 12px; }
    
    /* Hide key badge text on header, only show dot */
    .top-header .badge {
        padding: 0 8px;
        height: 24px;
        font-size: 10px;
        max-width: 98px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Dashboard 4 stats → 1col */
    .stat-grid { grid-template-columns: 1fr; }
    
    /* Form full width buttons */
    .form-row .btn { width: 100%; }
    .auth-bg-preview-row { align-items: flex-start; }
    .auth-bg-thumb { width: 100%; height: 120px; }
    
    /* Admin actions stacked */
    .actions-row .inline { display: block; width: 100%; }
    .actions-row form { display: block; width: 100%; }
    .actions-row .btn-mini { width: 100%; }
}

/* LARGE DESKTOP (≥ 1280px) */
@media (min-width: 1280px) {
    .page-content { padding: var(--space-10); }
}


/* ============================================================
   USER INFO PILL (header)
   ============================================================ */
.user-info-pill {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 4px 10px 4px 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
}
.user-info-pill .user-name-label {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
}

@media (max-width: 768px) {
    .user-info-pill { padding: 4px 8px 4px 4px; }
}


/* ============================================================
   LOADING SYSTEM
   ============================================================ */

/* Full-page loading screen (khi reload trang) */
.app-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity .3s ease, visibility .3s ease;
}
.app-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.app-loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
}
.app-loader-logo {
    width: 48px; height: 48px;
    background: linear-gradient(135deg, var(--brand-500), #a855f7);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    animation: logoPulse 1.6s ease-in-out infinite;
}
@keyframes logoPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(.92); opacity: .7; }
}
.app-loader-text {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}
.app-loader-bar {
    width: 160px;
    height: 2px;
    background: var(--bg-elevated);
    border-radius: 1px;
    overflow: hidden;
    position: relative;
}
.app-loader-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, var(--brand-500), transparent);
    animation: loaderBar 1.4s ease-in-out infinite;
}
@keyframes loaderBar {
    from { transform: translateX(-100%); }
    to   { transform: translateX(200%); }
}

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-elevated) 0%,
        var(--bg-hover) 50%,
        var(--bg-elevated) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-md);
    display: block;
}
@keyframes shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text:last-child { margin-bottom: 0; }
.skeleton-text.sm { height: 10px; }
.skeleton-text.lg { height: 18px; }
.skeleton-line-60 { width: 60%; }
.skeleton-line-80 { width: 80%; }
.skeleton-line-40 { width: 40%; }

.skeleton-stat {
    padding: var(--space-5);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
}

/* Inline button loading */
.btn.is-loading {
    pointer-events: none;
    position: relative;
    color: transparent !important;
}
.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    top: 50%; left: 50%;
    margin: -7px 0 0 -7px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btnSpin .7s linear infinite;
    color: #fff;
}
@keyframes btnSpin {
    to { transform: rotate(360deg); }
}

/* Mini spinner */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border-default);
    border-top-color: var(--brand-500);
    border-radius: 50%;
    animation: btnSpin .7s linear infinite;
}
.spinner.lg { width: 24px; height: 24px; border-width: 3px; }

/* Progress bar (top of page like youtube) */
.top-progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: transparent;
    z-index: 99998;
    pointer-events: none;
}
.top-progress::before {
    content: '';
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, var(--brand-500), #a855f7);
    box-shadow: 0 0 6px var(--brand-500);
    width: 0;
    transition: width .3s ease;
}
.top-progress.active::before { width: 70%; }
.top-progress.done::before { width: 100%; transition: width .15s ease; }

/* ============================================================
   TOAST NOTIFICATION SYSTEM
   ============================================================ */
.toast-container {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: 380px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toastIn .25s cubic-bezier(.4, 0, .2, 1);
    position: relative;
    overflow: hidden;
}
.toast.removing { animation: toastOut .2s ease forwards; }
@keyframes toastIn {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(120%); opacity: 0; }
}
.toast-icon {
    width: 20px; height: 20px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.toast-content { flex: 1; min-width: 0; }
.toast-title {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}
.toast-message {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.5;
}
.toast-close {
    flex-shrink: 0;
    width: 20px; height: 20px;
    color: var(--text-tertiary);
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px;
    transition: all var(--t-fast);
}
.toast-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.toast::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    height: 2px;
    background: currentColor;
    width: 100%;
    animation: toastProgress var(--toast-duration, 4s) linear forwards;
    transform-origin: left;
}
.toast.success::after { color: var(--success); }
.toast.error::after   { color: var(--danger); }
.toast.warning::after { color: var(--warning); }
.toast.info::after    { color: var(--info); }
@keyframes toastProgress {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon   { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon    { color: var(--info); }

/* ============================================================
   MODAL SYSTEM (override cũ + nâng cấp)
   ============================================================ */
.ui-modal {
    position: fixed;
    inset: 0; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: var(--space-5);
    animation: overlayIn .2s ease;
}
.ui-modal.show { display: flex; }
@keyframes overlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.ui-modal-box {
    width: 100%;
    max-width: 440px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: modalIn .25s cubic-bezier(.4, 0, .2, 1);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(.95) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ui-modal-icon {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    margin: 0 auto var(--space-4);
    flex-shrink: 0;
}
.ui-modal-icon.success { background: var(--success-soft); color: var(--success); }
.ui-modal-icon.error   { background: var(--danger-soft); color: var(--danger); }
.ui-modal-icon.warning { background: var(--warning-soft); color: var(--warning); }
.ui-modal-icon.info    { background: var(--info-soft); color: var(--info); }
.ui-modal-icon.brand   { background: rgba(99,102,241,.12); color: var(--brand-400); }

.ui-modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    text-align: center;
}
.ui-modal-body.left { text-align: left; }
.ui-modal-title {
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 600;
    margin-bottom: var(--space-2);
    letter-spacing: -0.005em;
}
.ui-modal-message {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: var(--space-2);
}
.ui-modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    flex-wrap: wrap;
}
.ui-modal-footer.center { justify-content: center; }
.ui-modal-footer .btn { min-width: 88px; }

/* Loading modal (only shows spinner) */
.ui-modal-loading .ui-modal-body {
    padding: var(--space-8) var(--space-6);
}
