:root {
    --paper: #f3f1ec;
    --paper-2: #ffffff;
    --ink: #16181d;
    --muted: #6d727c;
    --line: #e6e2d8;
    --stamp: #c81e1e;
    --stamp-dark: #9f1414;
    --moss: #1f3d32;
    --moss-2: #2c5647;
    --gold: #c4a265;
    --ok: #1f7a4d;
    --warn: #b45309;
    --shadow: 0 1px 2px rgba(22, 24, 29, 0.04), 0 12px 32px rgba(22, 24, 29, 0.06);
    --shadow-hover: 0 8px 28px rgba(22, 24, 29, 0.12);
    --side: 268px;
    --radius: 18px;
    --focus: 0 0 0 3px rgba(31, 61, 50, 0.22);
    --font: "Manrope", "Segoe UI", sans-serif;
    --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(900px 420px at 100% -10%, rgba(196, 162, 101, 0.12), transparent 50%),
        radial-gradient(700px 380px at -10% 110%, rgba(31, 61, 50, 0.08), transparent 46%),
        var(--paper);
    color: var(--ink);
    font-family: var(--font);
    letter-spacing: -0.01em;
}

a { color: var(--moss); text-decoration: none; }
a:hover { color: var(--stamp); }

.app {
    display: grid;
    grid-template-columns: var(--side) 1fr;
    min-height: 100vh;
}

.sidebar {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.04), transparent 28%),
        linear-gradient(180deg, #121613 0%, #0c100e 100%);
    color: #f3eee4;
    padding: 22px 16px 16px;
    position: sticky;
    top: 0;
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,0.04);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 2px;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin: 0 4px 14px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #fff;
    color: #c81e1e;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.brand-mark .kanku {
    width: 40px;
    height: 40px;
    display: block;
    object-fit: contain;
}

.menu-toggle {
    display: none;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: rgba(255,255,255,0.08);
    padding: 11px 10px;
    cursor: pointer;
    flex-direction: column;
    justify-content: space-between;
}
.menu-toggle span {
    display: block;
    height: 2px;
    background: #efe8db;
    border-radius: 2px;
}

.brand-text {
    font-family: var(--display);
    font-size: 18px;
    font-weight: 560;
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.brand-text small {
    display: block;
    font-family: var(--font);
    font-size: 11px;
    font-weight: 600;
    color: #b7b1a4;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 3px;
}

.brand-on-light { color: var(--ink); margin: 0 0 8px; }
.brand-on-light .brand-text small { color: var(--muted); }

.nav-link {
    color: #cfc8ba;
    padding: 9px 12px;
    border-radius: 12px;
    display: block;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}
.nav-link.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--stamp);
}

.nav-section {
    margin: 18px 12px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #8d938a;
}

.user-box {
    flex-shrink: 0;
    margin-top: 8px;
    padding: 14px 10px 8px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 8px 10px;
    align-items: center;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #24352e;
    color: #efe7d6;
    font-weight: 800;
    font-size: 13px;
}

.user-meta { min-width: 0; }
.user-name {
    font-size: 13px;
    font-weight: 700;
    color: #f4efe4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role { font-size: 12px; color: #a8a296; }
.user-box form { grid-column: 1 / -1; }

.logout-btn {
    margin-top: 4px;
    width: 100%;
    justify-content: center;
}

.content { padding: 32px 40px 72px; }

.page-title {
    font-family: var(--display);
    font-size: 36px;
    font-weight: 560;
    letter-spacing: -0.03em;
    margin: 0 0 6px;
}

.lede { color: var(--muted); margin: 0 0 24px; line-height: 1.5; }

.card {
    background: var(--paper-2);
    border: 1px solid rgba(22, 24, 29, 0.06);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.stat {
    position: relative;
    overflow: hidden;
}
.stat::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--stamp), var(--gold));
    opacity: 0.85;
}
.stat-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat .num {
    font-family: var(--display);
    font-size: 40px;
    font-weight: 650;
    letter-spacing: -0.04em;
    color: var(--ink);
    line-height: 1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-radius: 12px;
    padding: 10px 16px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    background: var(--moss);
    color: #fff;
    transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { background: var(--moss-2); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.stamp { background: var(--stamp); }
.btn.stamp:hover { background: var(--stamp-dark); }
.btn.ghost {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn.ghost:hover { background: #f7f5f0; color: var(--ink); }
.sidebar .btn.ghost.logout-btn {
    background: #efe8db;
    color: #141a16;
    border: 0;
}
.sidebar .btn.ghost.logout-btn:hover {
    background: #fff;
    color: #141a16;
}
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 10px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}
.table th {
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: #faf8f3; }
.table tbody tr:last-child td { border-bottom: 0; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    align-items: end;
}

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 650; color: var(--muted); }
input, select, textarea {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #8aa396;
    box-shadow: var(--focus);
}
textarea { min-height: 80px; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: #ece4d4;
}
.badge.ok { background: #d9f3e4; color: var(--ok); }
.badge.warn { background: #fde7c7; color: var(--warn); }
.badge.bad { background: #f8d5d2; color: var(--stamp); }

.flash { background: #e8f6ee; border: 1px solid #c5e5d1; padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; }
.error { background: #fbeceb; border: 1px solid #f0c7c2; padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; color: var(--stamp-dark); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 12% 12%, rgba(200, 30, 30, 0.14), transparent 38%),
        radial-gradient(circle at 88% 82%, rgba(31, 61, 50, 0.18), transparent 42%),
        var(--paper);
}

.login-card {
    width: min(440px, 92vw);
    background: var(--paper-2);
    border: 1px solid rgba(22, 24, 29, 0.06);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

.result-btns { display: flex; flex-wrap: wrap; gap: 6px; }

button.card.stat {
    width: 100%;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}
button.card.stat:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: transparent;
}

.metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 22px;
}
.metrics span {
    background: #fff;
    border: 1px solid rgba(22, 24, 29, 0.06);
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--muted);
    font-size: 14px;
    box-shadow: var(--shadow);
}
.metrics b { color: var(--ink); }

.fold, .month-fold {
    background: var(--paper-2);
    border: 1px solid rgba(22, 24, 29, 0.06);
    border-radius: var(--radius);
    padding: 8px 18px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.month-fold { box-shadow: none; margin-top: 8px; }
.fold > summary, .month-fold > summary {
    cursor: pointer;
    font-family: var(--display);
    font-size: 20px;
    padding: 10px 0;
    list-style: none;
}
.fold > summary::-webkit-details-marker,
.month-fold > summary::-webkit-details-marker { display: none; }
.month-fold > summary { font-size: 16px; font-family: var(--font); font-weight: 700; }

.group-block { margin: 12px 0 18px; }
.group-row { display: flex; gap: 8px; align-items: stretch; }
.group-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #faf8f3;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    color: inherit;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.group-btn:hover {
    border-color: transparent;
    color: inherit;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.group-name { font-weight: 800; font-size: 16px; color: var(--moss); }
.group-meta { color: var(--muted); font-size: 13px; }
.order-btns { display: flex; flex-direction: column; gap: 4px; }
.transfer-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
    padding-left: 6px;
}

.url-row { display: flex; gap: 8px; align-items: center; }
.url-row input { flex: 1; }

.col-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.col-toggles label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
th[draggable="true"] { cursor: grab; }

dialog.sheet {
    width: min(720px, 94vw);
    max-height: 84vh;
    border: 0;
    border-radius: 22px;
    padding: 0;
    background: var(--paper-2);
    color: var(--ink);
    box-shadow: 0 24px 80px rgba(12, 14, 16, 0.28);
}
dialog.sheet::backdrop { background: rgba(12, 14, 16, 0.48); backdrop-filter: blur(6px); }
.sheet-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 22px; font-family: var(--display); font-weight: 560; }
.sheet-body { padding: 8px 20px 20px; overflow: auto; }
.row-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.row-line:last-child { border-bottom: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

#qr-overlay {
    position: fixed;
    inset: 0;
    background: rgba(12, 12, 10, 0.82);
    display: grid;
    place-items: center;
    z-index: 40;
}
#qr-overlay[hidden] { display: none; }
.qr-box { width: min(420px, 92vw); text-align: center; color: #fff; }
#qr-video { width: 100%; border-radius: 16px; background: #000; }

.cal { margin-top: 8px; }
.cal-head, .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}
.cal-head span {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
    padding: 4px 0;
}
.cal-cell {
    min-height: 92px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
}
.cal-cell.is-out { opacity: 0.38; }
.cal-cell.is-today { box-shadow: 0 0 0 2px var(--stamp); }
.cal-num { font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.cal-ev {
    display: block;
    font-size: 12px;
    font-weight: 700;
    background: #efe8db;
    color: var(--moss);
    border-radius: 8px;
    padding: 4px 6px;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-ev:hover { background: var(--stamp); color: #fff; }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        height: auto;
        max-height: none;
        position: sticky;
        top: 0;
        z-index: 30;
        overflow: visible;
        padding: 12px 12px 10px;
        gap: 0;
    }
    .brand { margin: 0; }
    .menu-toggle { display: flex; }
    .sidebar-nav,
    .user-box { display: none; }
    .sidebar.is-open .sidebar-nav,
    .sidebar.is-open .user-box { display: block; }
    .sidebar.is-open .sidebar-nav {
        max-height: 60vh;
        overflow-y: auto;
        margin-top: 12px;
    }
    .sidebar.is-open .user-box {
        display: grid;
        margin-top: 8px;
    }
    .sidebar.is-open .menu-toggle span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
    .sidebar.is-open .menu-toggle span:nth-child(2) { opacity: 0; }
    .sidebar.is-open .menu-toggle span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }
    .menu-toggle span { transform-origin: center; transition: transform 0.15s ease, opacity 0.15s ease; }
    .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
    .content { padding: 16px 14px 48px; }
    .page-title { font-size: 28px; }
    .filters { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
    .filters .btn { grid-column: 1 / -1; min-height: 44px; }
    .table-wrap, .card { overflow-x: auto; }
    .result-btns .btn { min-height: 40px; flex: 1 1 46%; justify-content: center; }
    .transfer-row { padding-left: 0; }
    .group-row { flex-direction: column; }
    .order-btns { flex-direction: row; }
    dialog.sheet { width: 96vw; border-radius: 18px; }
    .metrics span { font-size: 13px; }
    .btn { min-height: 40px; }
    .nav-link { padding: 12px; }
    .cal-cell { min-height: 64px; padding: 4px; }
    .cal-ev { font-size: 10px; padding: 2px 4px; }
}

@media (max-width: 520px) {
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .filters { grid-template-columns: 1fr; }
}
