/* ============================================
   Milk Delivery Manager - Main Stylesheet
   Clean, professional, mobile-first design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ────────────────────────── */
:root {
    --primary:    #0284c7;
    --primary-dk: #0369a1;
    --primary-lt: #e0f2fe;
    --accent:     #f59e0b;
    --success:    #10b981;
    --danger:     #ef4444;
    --warning:    #f59e0b;

    --bg:         #f0f6ff;
    --card:       #ffffff;
    --border:     #dbeafe;
    --text:       #0f172a;
    --muted:      #64748b;
    --sidebar-bg: #0c1e35;
    --sidebar-txt:#94a3b8;
    --sidebar-act:#38bdf8;

    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);

    --radius:    10px;
    --radius-lg: 16px;
    --font:      'Sora', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --sidebar-w: 240px;
    --header-h:  60px;
}

/* ── Reset & Base ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

h1,h2,h3,h4 { line-height: 1.3; font-weight: 600; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

/* ── Layout ───────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .3s ease;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .logo-icon { font-size: 1.8rem; display: block; margin-bottom: 4px; }
.sidebar-brand h2 { color: #fff; font-size: .95rem; font-weight: 600; line-height: 1.2; }
.sidebar-brand span { color: var(--sidebar-txt); font-size: .75rem; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section-label {
    padding: 16px 20px 6px;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .1em;
    color: #475569;
    text-transform: uppercase;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-txt);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    border-left: 3px solid transparent;
    text-decoration: none;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav-item.active { color: var(--sidebar-act); background: rgba(56,189,248,.08); border-left-color: var(--sidebar-act); }
.nav-item .nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
    font-size: .8rem;
    color: var(--sidebar-txt);
}
.sidebar-footer a { color: #ef4444; font-weight: 500; text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

/* ── Main Content ─────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    height: var(--header-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}
.top-bar-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.top-bar-right { display: flex; align-items: center; gap: 12px; }
.top-bar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    color: var(--muted);
}
.top-bar-user .avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white;
    font-weight: 600;
    font-size: .8rem;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
}

.page-content {
    padding: 28px 24px;
    flex: 1;
}

/* ── Cards ────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── Stat Cards (Dashboard) ───────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; }
.stat-icon.green  { background: #d1fae5; }
.stat-icon.orange { background: #fef3c7; }
.stat-icon.red    { background: #fee2e2; }

.stat-info { flex: 1; min-width: 0; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ── Buttons ──────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: .875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger  { background: var(--danger); color: white; }
.btn-danger:hover  { background: #dc2626; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-icon { padding: 7px; }

/* ── Forms ────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: .9rem;
    color: var(--text);
    background: var(--bg);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(2,132,199,.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Tables ───────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--bg);
    padding: 11px 14px;
    text-align: left;
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fbff; }
tbody td { padding: 12px 14px; font-size: .875rem; vertical-align: middle; }
.td-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Badges ───────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: var(--primary-lt); color: #075985; }

/* ── Search & Filter Bar ──────────────────── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.search-input-wrap input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    background: var(--card);
    outline: none;
    transition: border-color .15s;
    font-family: var(--font);
}
.search-input-wrap input:focus { border-color: var(--primary); }
.search-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: .9rem;
    pointer-events: none;
}
.filter-select {
    padding: 9px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: var(--font);
    background: var(--card);
    color: var(--text);
    outline: none;
    cursor: pointer;
}

/* ── Modal ────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp .2s ease;
}
.modal.modal-lg { max-width: 700px; }
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background .15s;
}
.modal-close:hover { background: var(--bg); }
.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

/* ── Alerts ───────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: var(--primary-lt); color: #075985; border: 1px solid #7dd3fc; }

/* ── Delivery Grid (calendar-like) ───────── */
.delivery-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-top: 12px;
}
.day-cell {
    aspect-ratio: 1;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    cursor: pointer;
    transition: all .15s;
    background: var(--card);
    position: relative;
}
.day-cell:hover { border-color: var(--primary); }
.day-cell.has-delivery { background: var(--primary-lt); border-color: var(--primary); }
.day-cell.no-delivery  { background: #f9fafb; }
.day-cell.empty        { background: transparent; border: none; cursor: default; }
.day-cell .day-num     { font-weight: 600; font-size: .75rem; color: var(--text); }
.day-cell .day-qty     { font-size: .65rem; color: var(--primary); font-weight: 500; font-family: var(--font-mono); }

/* ── Month selector ───────────────────────── */
.month-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.month-nav select { min-width: 140px; }

/* ── Print styles ─────────────────────────── */
@media print {
    .sidebar, .top-bar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    body { background: white; }
    .card { box-shadow: none; border: 1px solid #e2e8f0; }
}

/* ── Toast Notifications ──────────────────── */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: #1e293b;
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: .875rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn .25s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 320px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
@keyframes toastIn {
    from { transform: translateX(20px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ── Empty State ──────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: .9rem; }

/* ── Responsive ───────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }
    .sidebar {
        transform: translateX(-240px);
        width: 240px;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .hamburger { display: block; }
    .page-content { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .delivery-grid { grid-template-columns: repeat(7, 1fr); }
    .modal { padding: 20px; }
    h1 { font-size: 1.35rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .top-bar { padding: 0 16px; }
    .top-bar-user span { display: none; }
}

/* ── Sidebar overlay for mobile ───────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* ── Utility ──────────────────────────────── */
.text-muted  { color: var(--muted); }
.text-success{ color: var(--success); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.font-mono { font-family: var(--font-mono); }
.fw-600 { font-weight: 600; }
.w-100 { width: 100%; }
