/* === Design Tokens === */
:root {
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: #dbeafe;
    --success: #22c55e;
    --success-soft: #dcfce7;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --danger: #ef4444;
    --danger-soft: #fee2e2;
    --text: #1e293b;
    --text-secondary: #475569;
    --muted: #94a3b8;
    --border: #e2e8f0;
    --bg: #f8fafc;
    --panel: #ffffff;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-muted: #94a3b8;
    --sidebar-active: #334155;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); background: var(--bg); }

/* === Sidebar === */
.sidebar { width: 240px; min-height: 100vh; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transition: transform 0.25s ease; }
.sidebar-header { padding: 1.25rem 1rem; display: flex; align-items: center; gap: 0.75rem; border-bottom: 1px solid #334155; }
.sidebar-logo { width: 36px; height: 36px; background: var(--accent); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem; color: #fff; flex-shrink: 0; }
.sidebar-title { font-weight: 600; font-size: 1rem; }
.sidebar-nav { flex: 1; padding: 0.75rem 0; }
.sidebar-nav a { display: flex; align-items: center; justify-content: space-between; padding: 0.625rem 1rem; color: var(--sidebar-muted); text-decoration: none; font-size: 0.875rem; transition: all 0.15s; }
.sidebar-nav a:hover { background: var(--sidebar-active); color: #f1f5f9; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; border-left: 3px solid var(--accent); }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid #334155; display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-footer-link { color: var(--sidebar-muted); text-decoration: none; font-size: 0.8rem; padding: 0.375rem 0; }
.sidebar-footer-link:hover { color: #f1f5f9; }
.sidebar-footer-link.logout { color: #f87171; }
.sidebar-footer-link.logout:hover { color: #fca5a5; }

/* === Mobile Header === */
.mobile-header { display: none; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: var(--sidebar-bg); color: #fff; z-index: 60; padding: 0 1rem; align-items: center; gap: 0.75rem; }
.hamburger-btn { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 0.5rem; }
.mobile-header .sidebar-logo { width: 32px; height: 32px; font-size: 0.9rem; }
.mobile-header-title { font-weight: 600; font-size: 0.9rem; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 49; }

/* === Main Content === */
.main-content { margin-left: 240px; flex: 1; padding: 2rem; min-height: 100vh; }

/* === Page === */
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 1.5rem; }
.page-header { margin-bottom: 1.5rem; }
.back-link { color: var(--muted); text-decoration: none; font-size: 0.8rem; display: inline-block; margin-bottom: 0.5rem; }
.back-link:hover { color: var(--accent); }

/* === Alerts Bar === */
.alerts-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.alert-chip { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.375rem 0.75rem; border-radius: var(--radius-full); font-size: 0.8rem; font-weight: 500; text-decoration: none; transition: opacity 0.15s; }
.alert-chip:hover { opacity: 0.85; }
.alert-chip--danger { background: var(--danger-soft); color: #991b1b; }
.alert-chip--warning { background: var(--warning-soft); color: #92400e; }

/* === Stats Grid === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stats-grid--4 { grid-template-columns: repeat(4, 1fr); }
.stats-grid--5 { grid-template-columns: repeat(5, 1fr); }
.stat-card { background: var(--panel); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.stat-card--sm { padding: 1rem; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-card--sm .stat-value { font-size: 1.5rem; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

/* === Today Bar === */
.today-bar { background: var(--accent-soft); padding: 0.5rem 1rem; border-radius: var(--radius-md); margin-bottom: 1rem; font-size: 0.85rem; display: inline-flex; gap: 0.5rem; }
.today-label { color: var(--accent); font-weight: 600; }
.today-value { color: var(--text); }

/* === Quick Actions === */
.quick-actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.quick-action { padding: 0.5rem 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-secondary); text-decoration: none; font-size: 0.85rem; font-weight: 500; transition: all 0.15s; }
.quick-action:hover { border-color: var(--accent); color: var(--accent); }

/* === Cards === */
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card { background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 1rem; }
.card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); padding: 1rem 1.25rem 0; }
.card-body { padding: 0.75rem 1.25rem 1.25rem; }

/* === Detail Grid === */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid #f1f5f9; font-size: 0.85rem; }
.detail-label { color: var(--muted); font-weight: 500; }

/* === Table === */
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: 0.5rem 0.5rem 0.5rem 0; border-bottom: 1px solid var(--border); }
.table td { padding: 0.5rem 0.5rem 0.5rem 0; border-bottom: 1px solid #f1f5f9; color: var(--text-secondary); }
.table-row-link { cursor: pointer; transition: background 0.1s; }
.table-row-link:hover { background: var(--bg); }

/* === Badges === */
.badge { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.5rem; border-radius: var(--radius-sm); text-transform: uppercase; letter-spacing: 0.03em; }
.badge--sm { font-size: 0.65rem; padding: 0.15rem 0.4rem; }
.badge--active, .badge--trial, .badge--completed, .badge--delivered { background: var(--success-soft); color: #166534; }
.badge--suspended, .badge--past_due, .badge--canceled, .badge--processing, .badge--confirmed { background: var(--warning-soft); color: #92400e; }
.badge--disabled, .badge--expired, .badge--failed, .badge--cancelled { background: var(--danger-soft); color: #991b1b; }
.badge--invited, .badge--created, .badge--pending { background: var(--accent-soft); color: #1e40af; }
.badge--locked { background: #fecaca; color: #991b1b; }
.badge--shipped { background: #e0e7ff; color: #3730a3; }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.375rem 0.75rem; border: none; border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 500; cursor: pointer; transition: all 0.15s; text-decoration: none; }
.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: #16a34a; }
.btn--warning { background: var(--warning); color: #fff; }
.btn--warning:hover { background: #d97706; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #dc2626; }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--bg); }

/* === Action Buttons === */
.action-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.inline-form { display: flex; gap: 0.375rem; align-items: center; }
.input-sm { width: 60px; padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.75rem; }
.select-sm { padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.75rem; background: var(--panel); }

/* === Filter Bar === */
.filter-bar { margin-bottom: 1.25rem; }
.filter-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-input { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.85rem; min-width: 220px; }
.filter-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.filter-select { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.85rem; background: var(--panel); }
.btn-filter { padding: 0.5rem 1rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-md); font-size: 0.85rem; cursor: pointer; }
.btn-filter:hover { background: var(--accent-hover); }
.btn-clear { padding: 0.5rem 1rem; color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.btn-clear:hover { color: var(--text-secondary); }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-md); font-size: 0.85rem; margin-bottom: 1rem; }
.alert--success { background: var(--success-soft); color: #166534; }
.alert--error { background: var(--danger-soft); color: #991b1b; }

/* === Empty States === */
.empty-state-inline { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

/* === Pagination === */
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }

/* === Timeline === */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 1rem; padding-left: 0.75rem; }
.timeline-dot { position: absolute; left: -1.5rem; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--border); border: 2px solid var(--panel); }
.timeline-dot--pending, .timeline-dot--confirmed { background: var(--accent); }
.timeline-dot--processing, .timeline-dot--shipped { background: var(--warning); }
.timeline-dot--delivered, .timeline-dot--completed { background: var(--success); }
.timeline-dot--cancelled, .timeline-dot--failed { background: var(--danger); }
.timeline-header { display: flex; align-items: center; gap: 0.375rem; margin-bottom: 0.25rem; }
.timeline-arrow { color: var(--muted); font-size: 0.75rem; }
.timeline-time { font-size: 0.75rem; color: var(--muted); }
.timeline-note { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; padding: 0.25rem 0.5rem; background: var(--bg); border-radius: var(--radius-sm); }

/* === Order Items === */
.item-product { display: flex; align-items: center; gap: 0.75rem; }
.item-thumb { width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover; }
.item-attrs { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-top: 0.25rem; }
.item-attr-tag { font-size: 0.7rem; padding: 0.1rem 0.4rem; background: var(--bg); border-radius: var(--radius-sm); color: var(--muted); }

/* === Text utilities === */
.text-muted { color: var(--muted); }
.text-success { color: #16a34a; }
.text-warning { color: #d97706; }
.text-danger { color: #dc2626; }

/* === Auth Pages === */
.auth-card { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow-md); padding: 2.5rem; width: 100%; max-width: 400px; }
.auth-card--wide { max-width: 480px; }
.auth-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.auth-header h1 { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.auth-logo { width: 40px; height: 40px; background: var(--accent); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.25rem; color: #fff; }
.auth-subtitle { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.25rem; }
.auth-error { background: var(--danger-soft); color: #991b1b; padding: 0.75rem 1rem; border-radius: var(--radius-md); font-size: 0.85rem; margin-bottom: 1rem; }
.auth-back-link { display: block; text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 1rem; text-decoration: none; }
.auth-back-link:hover { color: var(--accent); }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.375rem; }
.form-group input { width: 100%; padding: 0.625rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.875rem; outline: none; transition: border-color 0.15s; box-sizing: border-box; }
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.totp-input { text-align: center; font-size: 1.5rem; letter-spacing: 0.5em; font-weight: 600; }
.btn-primary { width: 100%; padding: 0.625rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-md); font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-primary:hover { background: var(--accent-hover); }

/* === 2FA Setup === */
.setup-steps { margin-bottom: 1.5rem; }
.setup-step { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.step-number { width: 24px; height: 24px; background: var(--accent); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; flex-shrink: 0; }
.setup-step p { font-size: 0.85rem; color: var(--text-secondary); }
.qr-container { text-align: center; margin: 1rem 0; }
.secret-display { background: var(--bg); padding: 0.75rem; border-radius: var(--radius-md); font-family: monospace; font-size: 0.8rem; word-break: break-all; text-align: center; color: var(--text-secondary); margin-bottom: 1rem; }

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .mobile-header { display: flex; }
    .main-content { margin-left: 0; padding: 1rem; padding-top: 72px; }
    .stats-grid, .stats-grid--4, .stats-grid--5 { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .cards-row { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.5rem; }
    .stat-card--sm .stat-value { font-size: 1.25rem; }
    .filter-form { flex-direction: column; align-items: stretch; }
    .filter-input { min-width: unset; }
    .quick-actions { flex-direction: column; }
    .table { font-size: 0.8rem; }
    .table th, .table td { padding: 0.375rem 0.25rem; }
}

/* === Confirmation Modal === */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    display: flex; align-items: center; justify-content: center;
}
.modal-dialog {
    background: var(--bg-card); border-radius: 0.75rem; padding: 1.5rem;
    max-width: 400px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.modal-dialog h3 { margin: 0 0 0.75rem; font-size: 1.125rem; color: var(--text-primary); }
.modal-dialog p { margin: 0 0 1.25rem; color: var(--text-secondary); font-size: 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
