:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --primary: #1e40af;
    --primary-2: #2563eb;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --warning: #f59e0b;
    --success: #10b981;
    --info: #0ea5e9;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
    --header-h: 56px;
    --bottomnav-h: 64px;
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0));
}

a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem 0; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    height: var(--header-h);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 50;
    box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top, 0);
}
.app-header .title {
    flex: 1;
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-header .icon-btn {
    background: transparent;
    border: 0;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
}
.app-header .icon-btn:active { background: rgba(255,255,255,.15); }
.app-header a { color: #fff; }

/* ---------- Drawer (Sidebar) ---------- */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 90;
}
.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    max-width: 85vw;
    background: var(--surface);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--primary);
    color: #fff;
}
.drawer-header .brand {
    font-size: 1.15rem;
    font-weight: 600;
}
.drawer-header .user {
    font-size: .85rem;
    opacity: .9;
    margin-top: 4px;
}
.drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.drawer-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    color: var(--text);
    font-size: .98rem;
    border-left: 3px solid transparent;
}
.drawer-nav a:hover { background: var(--surface-2); text-decoration: none; }
.drawer-nav a.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}
.drawer-nav .icon { width: 22px; text-align: center; }
.drawer-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: .8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* ---------- Main ---------- */
.app-main {
    padding: 14px;
    max-width: 900px;
    margin: 0 auto;
}

/* ---------- Bottom Nav (mobile) ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottomnav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -1px 4px rgba(0,0,0,.04);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: .72rem;
    gap: 2px;
    text-decoration: none;
    padding: 6px 4px;
}
.bottom-nav a .icon { font-size: 1.35rem; line-height: 1; }
.bottom-nav a.active { color: var(--primary); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}
.card-title {
    font-weight: 600;
    margin: 0 0 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.card-row:last-child { border-bottom: 0; }

/* ---------- Stats grid ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}
.stat-card .label {
    font-size: .78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.stat-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 2px;
    color: var(--text);
}
.stat-card.accent .value { color: var(--primary); }
.stat-card.success .value { color: var(--success); }
.stat-card.warning .value { color: var(--warning); }
.stat-card.danger .value { color: var(--danger); }

/* ---------- List items ---------- */
.list-item {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    gap: 12px;
    align-items: center;
}
.list-item:hover { background: var(--surface-2); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .main .title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-item .main .sub {
    font-size: .85rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.list-item .right { text-align: right; font-size: .85rem; color: var(--text-muted); }
.list-item a { color: inherit; text-decoration: none; display: contents; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    font-weight: 500;
    font-size: .95rem;
    cursor: pointer;
    min-height: 42px;
    text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.warning { background: var(--warning); }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn.full { width: 100%; }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: .85rem; }

.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom, 0));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    border: 0;
    box-shadow: var(--shadow-lg);
    z-index: 30;
    text-decoration: none;
}
.fab:hover { text-decoration: none; color: #fff; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: .9rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    min-height: 44px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-2);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- Search / toolbar ---------- */
.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}
.toolbar .search {
    flex: 1;
    position: relative;
}
.toolbar .search input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    font-size: .95rem;
    min-height: 42px;
}
.toolbar .search::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: .9rem;
    opacity: .6;
}

/* ---------- Status badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .75rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
}

/* ---------- Flash messages ---------- */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-size: .9rem;
    border-left: 4px solid;
}
.flash.success { background: #ecfdf5; color: #065f46; border-color: var(--success); }
.flash.error { background: #fef2f2; color: #991b1b; border-color: var(--danger); }
.flash.warning { background: #fffbeb; color: #92400e; border-color: var(--warning); }
.flash.info { background: #eff6ff; color: #1e40af; border-color: var(--info); }

/* ---------- Auth ---------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
    padding: 20px;
}
.auth-card {
    background: var(--surface);
    padding: 28px 22px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
}
.auth-card h1 {
    text-align: center;
    margin-bottom: 4px;
    color: var(--primary);
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .9rem;
    margin-bottom: 22px;
}

/* ---------- Calendar ---------- */
.calendar {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px;
    overflow: hidden;
}
.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px 12px 4px;
}
.calendar-head .month { font-weight: 600; font-size: 1.05rem; }
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.calendar-grid .dow {
    font-size: .72rem;
    color: var(--text-muted);
    text-align: center;
    padding: 4px 0;
    font-weight: 500;
    text-transform: uppercase;
}
.calendar-cell {
    min-height: 60px;
    padding: 4px;
    border-radius: 6px;
    background: var(--surface-2);
    font-size: .8rem;
    position: relative;
}
.calendar-cell.outside { opacity: .35; }
.calendar-cell.today { background: var(--primary-light); border: 1px solid var(--primary); }
.calendar-cell .day { font-weight: 600; font-size: .85rem; }
.calendar-cell .dots {
    display: flex;
    gap: 2px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.calendar-cell .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.calendar-cell .ev {
    font-size: .68rem;
    background: var(--primary);
    color: #fff;
    border-radius: 3px;
    padding: 1px 3px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Detail layout ---------- */
.detail-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}
.detail-head .meta {
    color: var(--text-muted);
    font-size: .9rem;
    margin-top: 4px;
}

.kvp { font-size: .9rem; margin-bottom: 8px; }
.kvp .k { color: var(--text-muted); }

.empty {
    text-align: center;
    padding: 24px 12px;
    color: var(--text-muted);
    font-size: .92rem;
}

/* ---------- Responsive: tablet+ ---------- */
@media (min-width: 768px) {
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }
    .app-header .menu-toggle { display: none; }
    .drawer {
        transform: translateX(0);
        position: sticky;
        top: 0;
        height: 100vh;
        box-shadow: none;
        border-right: 1px solid var(--border);
    }
    .drawer-backdrop { display: none; }
    .app-layout {
        display: grid;
        grid-template-columns: var(--sidebar-w) 1fr;
    }
    .app-main { padding: 22px; max-width: none; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .form-row { grid-template-columns: 1fr 1fr 1fr; }
    .fab { bottom: 24px; right: 24px; }
}

@media (max-width: 767px) {
    .app-layout { display: block; }
    .drawer-mount { display: contents; }
}
