:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-alt: #f8f9fb;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --border: #e2e5ea;
    --border-light: #eef0f3;
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --danger-hover: #b91c1c;
    --danger-border: #fecaca;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --warning-border: #fde68a;
    --orange: #ea580c;
    --orange-light: #fff7ed;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.07);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Navbar --- */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
}
.navbar .brand svg { color: var(--primary); }
.navbar nav { display: flex; align-items: center; gap: 4px; }
.navbar nav a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s;
}
.navbar nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.navbar nav a.active { background: var(--primary-light); color: var(--primary); }
.navbar nav a svg { width: 16px; height: 16px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px; }

/* --- Stats strip --- */
.stats-strip {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    transition: transform 0.1s, box-shadow 0.1s;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.icon-blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.icon-amber { background: var(--warning-light); color: var(--warning); }
.stat-icon.icon-orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.icon-indigo { background: #eef2ff; color: #4f46e5; }
.stat-icon.icon-red { background: var(--danger-light); color: var(--danger); }
.stat-info .stat-number { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-info .stat-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.stat-card.stat-critical {
    border-color: var(--danger-border);
    background: linear-gradient(135deg, var(--danger-light) 0%, var(--surface) 100%);
}
.stat-card.stat-critical .stat-number { color: var(--danger); }
.stat-card.stat-warn {
    border-color: var(--warning-border);
    background: linear-gradient(135deg, var(--warning-light) 0%, var(--surface) 100%);
}
.stat-card.stat-warn .stat-number { color: var(--warning); }

/* --- Card --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface-alt);
}
.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-header h2 svg { width: 18px; height: 18px; color: var(--text-muted); }
.card-body { padding: 0; }
.card-body-padded { padding: 20px; }

/* --- Filter bar --- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface);
}
.filter-bar a {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border);
    color: var(--text-muted);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.filter-bar a:hover { background: var(--surface-alt); text-decoration: none; color: var(--text); }
.filter-bar a.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.filter-bar .filter-count {
    background: rgba(0,0,0,0.08);
    padding: 0 6px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
}
.filter-bar a.active .filter-count {
    background: rgba(255,255,255,0.25);
}

/* --- Table --- */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
th, td {
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}
th {
    background: var(--surface-alt);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    position: sticky;
    top: 0;
}
tr:hover td { background: #f9fafb; }

/* Row urgency highlights */
tr.row-overdue { background: #fef2f2; }
tr.row-overdue:hover td { background: #fee2e2; }
tr.row-today { background: #fffbeb; }
tr.row-today:hover td { background: #fef3c7; }
tr.row-urgent { background: #fff7ed; }
tr.row-urgent:hover td { background: #ffedd5; }

.customer-cell { font-weight: 600; }
.sub-name { display: flex; align-items: center; gap: 6px; }
.sub-name svg { width: 14px; height: 14px; color: var(--text-light); flex-shrink: 0; }
.sub-url { font-size: 0.75rem; color: var(--text-light); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.sub-url svg { width: 12px; height: 12px; }
.cycle-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--surface-alt);
    color: var(--text-muted);
    border: 1px solid var(--border-light);
}
.cycle-badge svg { width: 12px; height: 12px; }
.days-cell { font-weight: 700; font-variant-numeric: tabular-nums; }
.days-cell.days-negative { color: var(--danger); }
.days-cell.days-zero { color: var(--warning); }
.days-cell.days-low { color: var(--orange); }

/* --- Status badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.status-overdue { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.status-today { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.status-urgent { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.status-warning { background: #fefce8; color: #854d0e; border: 1px solid #fef08a; }
.status-soon { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.status-safe { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,0.3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); text-decoration: none; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; text-decoration: none; color: #fff; }
.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline:hover { background: var(--surface-alt); text-decoration: none; color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 4px 8px; }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }

/* --- Actions cell --- */
.actions { display: flex; gap: 4px; flex-wrap: nowrap; align-items: center; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    margin-bottom: 5px;
    font-size: 0.88rem;
}
.form-group label svg { width: 14px; height: 14px; color: var(--text-muted); }
.form-group input,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* --- Alerts --- */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* --- Login page --- */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
    background: linear-gradient(135deg, #f0f2f5 0%, #dbeafe 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    overflow: hidden;
}
.login-card .login-header {
    background: var(--surface-alt);
    padding: 24px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
}
.login-card .login-header h1 {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.login-card .login-header h1 svg { color: var(--primary); }
.login-card .login-body { padding: 24px; }

/* --- Empty state --- */
.empty-state {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; color: var(--border); margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; margin-bottom: 16px; }

/* --- Responsive --- */
@media (max-width: 900px) {
    .stats-strip { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .navbar { padding: 0 12px; height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
    .navbar nav { flex-wrap: wrap; }
    .stats-strip { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { padding: 10px 12px; }
    th, td { padding: 8px 10px; }
}
@media (max-width: 480px) {
    .stats-strip { grid-template-columns: 1fr; }
    .container { padding: 12px 8px; }
    .actions { flex-wrap: wrap; }
}
