:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --sidebar: #0f172a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Layout with sidebar ===== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
}
.brand { padding: 20px 20px; font-size: 18px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; color: #64748b; padding: 14px 12px 6px; letter-spacing: .05em; }
.side-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px; color: #cbd5e1;
    font-size: 14px; margin-bottom: 2px; transition: all .15s;
}
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: var(--primary); color: #fff; }
.side-nav .ic { font-size: 16px; }
.side-foot { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user { font-size: 13px; color: #94a3b8; margin-bottom: 8px; }
.logout { color: #f87171; font-size: 13px; }

.main { flex: 1; margin-left: 220px; display: flex; flex-direction: column; }
.topbar {
    background: var(--card); border-bottom: 1px solid var(--border);
    padding: 16px 28px; position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 20px; font-weight: 600; }
.content { padding: 24px 28px; max-width: 1400px; }

/* ===== Auth pages ===== */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
}
.auth-card { background: #fff; padding: 40px; border-radius: 16px; width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-card h1 { text-align: center; margin-bottom: 8px; color: var(--primary); font-size: 24px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* ===== Cards ===== */
.card { background: var(--card); border-radius: 12px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--border); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-size: 16px; font-weight: 600; }

/* ===== Stats grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); padding: 20px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--border); }
.stat-value { font-size: 30px; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.stat-card.green .stat-value { color: var(--success); }
.stat-card.orange .stat-value { color: var(--warning); }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: #475569; }
input, select, textarea {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; }

/* ===== Buttons ===== */
.btn {
    display: inline-block; padding: 9px 18px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 500; cursor: pointer; background: #e2e8f0; color: #334155;
    transition: all .15s; text-decoration: none; line-height: 1.4;
}
.btn:hover { background: #cbd5e1; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ===== Alerts ===== */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; }
.table th { background: #f8fafc; padding: 11px 14px; text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.table tr:hover td { background: #f8fafc; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }

h2 { font-size: 18px; margin: 20px 0 14px; }
h4 { font-size: 14px; margin-bottom: 10px; }
.text-center { text-align: center; }
.mt-2 { margin-top: 12px; }

.heartbeat { display: flex; justify-content: space-between; align-items: center; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,.2); }
.dot.off { background: #94a3b8; }

@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .brand { font-size: 0; padding: 20px 0; text-align: center; }
    .brand::before { content: '🐴'; font-size: 22px; }
    .side-nav a { justify-content: center; }
    .side-nav a span:not(.ic) { display: none; }
    .nav-section, .side-user, .logout { display: none; }
    .main { margin-left: 60px; }
}
