:root {
    --brand: #d3122a;
    --brand-dark: #8c1e30;
    --brand-mid: #e44556;
    --brand-soft: #fdecee;
    --brand-soft-2: #f8dde1;
    --ink: #2a1820;
    --muted: #8a6f76;
    --line: #f0dde1;
    --bg: #fbf7f8;
    --surface: #ffffff;
    --sidebar-bg: #f8f2f3;
    --danger: #d3122a;
    --warn: #a56a12;
    --success: #2e9b57;
    --shadow: 0 8px 28px rgba(140, 30, 48, 0.08);
    --shadow-sm: 0 2px 10px rgba(140, 30, 48, 0.06);
    --radius: 16px;
    --font: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: linear-gradient(180deg, #fff 0%, var(--bg) 42%, #f7eef0 100%);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font); font-weight: 700; letter-spacing: -0.02em; margin: 0; color: var(--ink); }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
p { margin: 0; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 248px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--line);
    padding: 0 12px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .28s ease;
}
.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 92px;
    padding: 14px 8px 12px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--line);
}
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 84px;
    height: 84px;
    object-fit: contain;
    display: block;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; padding-right: 2px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--ink);
    font-weight: 500;
    font-size: 14px;
}
.nav-link:hover { background: rgba(211, 18, 42, 0.08); color: var(--brand-dark); text-decoration: none; }
.nav-link svg { width: 18px; height: 18px; fill: none; stroke: var(--brand); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-link.active {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 8px 20px rgba(211, 18, 42, 0.28);
}
.nav-link.active svg { stroke: #fff; }
.nav-group { display: grid; gap: 2px; }
.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 14px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--ink);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-align: left;
}
.nav-group-toggle svg { width: 18px; height: 18px; fill: none; stroke: var(--brand); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-group-toggle:hover { background: rgba(211, 18, 42, 0.08); color: var(--brand-dark); }
.nav-group-toggle.active { color: var(--brand-dark); background: rgba(211, 18, 42, 0.06); }
.nav-chevron { margin-left: auto; transition: transform .18s ease; stroke: var(--muted) !important; }
.nav-group.open .nav-chevron { transform: rotate(180deg); }
.nav-sub { display: none; gap: 2px; padding: 0 0 4px 12px; }
.nav-group.open .nav-sub { display: grid; }
.nav-sub-link { padding: 9px 14px 9px 28px; font-size: 13px; position: relative; }
.nav-sub-link::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #e7c5cb;
    transform: translateY(-50%);
}
.nav-sub-link.active::before { background: #fff; }
.sidebar-foot {
    margin-top: auto;
    padding: 14px 8px 6px;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 8px;
}
.sidebar-foot .btn { width: 100%; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 28px;
    position: sticky;
    top: 0;
    z-index: 25;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.topbar-spacer { flex: 1; }
.top-search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: min(320px, 46vw);
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
}
.top-search svg, .icon-btn svg, .bell svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.top-search input { border: 0; background: transparent; width: 100%; padding: 10px 0; outline: none; }
.icon-btn, .bell {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--brand);
    display: grid;
    place-items: center;
    position: relative;
    text-decoration: none;
}
.icon-btn:hover, .bell:hover { background: var(--brand-soft); text-decoration: none; }
.bell span {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--brand);
    color: white;
    border-radius: 99px;
    font-size: 0.68rem;
    min-width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    padding: 0 4px;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px 4px 10px;
    margin-left: 8px;
    border-left: 1px solid var(--line);
}
.topbar-user .meta { text-align: right; line-height: 1.2; }
.topbar-user strong { display: block; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.topbar-user small { color: var(--muted); font-size: 12px; }
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand);
    display: grid;
    place-items: center;
    font-weight: 700;
    border: 2px solid rgba(211, 18, 42, 0.12);
}
.menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
}
.menu-btn span { display: block; width: 16px; height: 2px; background: var(--ink); margin: 4px auto; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(42, 24, 32, 0.35); z-index: 30; }

.content { padding: 20px 28px 48px; flex: 1; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.lede { color: var(--muted); margin-top: 4px; font-size: 14px; max-width: 68ch; }
.page-actions, .form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(211, 18, 42, 0.22); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-sm { padding: 7px 12px; border-radius: 10px; font-size: 13px; }

.card, .stat, .period-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card { padding: 16px; margin-bottom: 16px; }
.card-head, .cal-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}
.card-head.is-foldable { cursor: pointer; border-radius: 10px; }
.card-head.is-foldable:hover h2 { color: var(--brand-dark); }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.fold-chevron, .card-head .fold-mark {
    width: 16px;
    height: 16px;
    display: inline-flex;
    transition: transform .18s ease;
    flex-shrink: 0;
}
.fold-chevron, .card-head .fold-mark svg { width: 16px; height: 16px; }
.card-head .fold-mark svg, .fold-chevron {
    fill: none;
    stroke: var(--brand);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.card.is-collapsed .fold-mark { transform: rotate(-90deg); }
.card.is-collapsed > :not(.card-head) { display: none; }
.add-panel[hidden] { display: none !important; }
.card.is-adding > .section-main,
.card.is-adding > .card-head .js-open-add { display: none; }
.card.is-collapsed .card-head { margin-bottom: 0; }
.fold { border-top: 1px solid var(--line); }
.fold:first-child { border-top: 0; }
.fold-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 12px 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.02em;
}
.fold-body { display: none; padding-bottom: 8px; }
.fold.open .fold-body { display: block; }
.fold.open .fold-chevron { transform: rotate(180deg); }
.card-head p, .hint, .empty-line { color: var(--muted); margin: 4px 0 0; }
.stat-grid, .mini-stats, .fact-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { padding: 18px; position: relative; overflow: hidden; }
.stat::after {
    content: "";
    position: absolute;
    right: -18px;
    top: -18px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(211, 18, 42, 0.12), transparent 70%);
}
.stat span, .fact-grid span, .mini-stats span { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat strong, .mini-stats strong {
    display: block;
    font-size: 26px;
    margin-top: 8px;
    letter-spacing: -0.03em;
    color: var(--brand-dark);
}
.stat small { color: var(--muted); }
.mini-stats { margin-top: 8px; }
.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; }
.stack-cards { display: flex; flex-direction: column; }
.bars { display: flex; align-items: flex-end; gap: 12px; min-height: 180px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar span { width: 100%; max-width: 36px; background: linear-gradient(180deg, #f3a0ab, var(--brand)); border-radius: 8px 8px 3px 3px; display: block; }
.bar b { font-weight: 600; }
.bar small { color: var(--muted); }
.mix-row { margin-bottom: 14px; }
.mix-row div { display: flex; justify-content: space-between; gap: 8px; }
.mix-row span { color: var(--muted); }
.mix-row i { display: block; height: 8px; margin-top: 6px; background: var(--brand); border-radius: 99px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #fdf8f8; }
tbody tr:hover { background: #fdf8f8; }
td small, .fact-grid small { display: block; color: var(--muted); }
.code { font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.row-actions a, .text-btn { margin-right: 10px; background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font-weight: 600; }
.text-btn.danger, .danger { color: var(--brand-dark); }

.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    background: var(--brand-soft);
    color: var(--brand-dark);
}
.pill-teal { background: #e6f7ed; color: #1b7a3e; }
.pill-coral, .pill-gold { background: #fff4d8; color: #8a5a00; }
.pill-muted { background: #f3ecee; color: var(--muted); }
.pill-ink { background: var(--brand-soft); color: var(--brand-dark); }

.filters, .settings-form, .upload-row, .grid-2, .grid-3 { display: grid; gap: 14px; }
.filters, .settings-form, .upload-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; margin-bottom: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field i { color: var(--brand); font-style: normal; }
.field input, .field select, .field textarea, .client-filter {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    padding: 11px 12px;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .client-filter:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(211, 18, 42, 0.12);
}
.field[hidden] { display: none; }
.form-card .grid-2, .form-card .grid-3 { margin-bottom: 12px; }
.form-actions { margin-top: 14px; }
.form-errors { background: #fdecec; color: #9b2c2c; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.form-errors ul { margin: 6px 0 0; padding-left: 18px; }
.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; background: #e6f7ed; color: #1b7a3e; font-weight: 500; }
.flash-error { background: #fdecec; color: #9b2c2c; }
.segment { display: flex; gap: 6px; flex-wrap: wrap; }
.segment a { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; background: #fff; }
.segment a.is-on { background: var(--brand-soft); color: var(--brand-dark); border-color: #f0c4cb; }
.empty { text-align: center; padding: 28px 8px 18px; color: var(--muted); }
.empty h2 { margin-bottom: 6px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.pager .is-disabled { pointer-events: none; opacity: 0.4; }
.fact-grid { grid-template-columns: repeat(3, 1fr); }
.fact-grid strong { display: block; font-weight: 600; color: var(--ink); }
.address, .notes { margin: 14px 0 0; }
.desk-item, .notice, .link-list li, .doc-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    color: inherit;
    text-decoration: none;
}
.desk-item span, .notice span, .notice small { color: var(--muted); }
.notice.is-read { opacity: 0.62; }
.link-list, .doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list form { margin: 0; }
.inline-status { display: flex; gap: 12px; align-items: end; }
.inline-status .field { min-width: 220px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head span { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; padding: 0 4px 6px; }
.cal-day { min-height: 108px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: #fff; }
.cal-day.is-out { opacity: 0.45; }
.cal-day.is-today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.chip { display: block; margin-top: 4px; border-radius: 7px; padding: 2px 5px; font-size: 0.72rem; line-height: 1.3; color: var(--ink); text-decoration: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip:hover { text-decoration: none; }
.chip-gold { background: #fff4d8; }
.chip-teal { background: #e6f7ed; }
.chip-coral { background: var(--brand-soft); }
.cal-legend { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.dot-gold { background: #c48a1a; }
.dot-teal { background: var(--success); }
.dot-coral { background: var(--brand); }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(800px 400px at 15% 10%, rgba(211, 18, 42, 0.14), transparent 55%),
        radial-gradient(700px 360px at 90% 85%, rgba(140, 30, 48, 0.08), transparent 50%),
        linear-gradient(160deg, #fff, #f8eef0 55%, #fbf7f8);
}
.login-card {
    width: min(440px, 100%);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 36px 32px;
    box-shadow: 0 28px 70px rgba(140, 30, 48, 0.12);
}
.login-card .logo { width: 112px; height: 112px; object-fit: contain; display: block; margin: 0 auto 8px; }
.login-card h1 { text-align: center; font-size: 24px; margin: 8px 0 6px; color: var(--brand-dark); }
.login-card .lead { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.login-card form { display: grid; gap: 14px; }

@media (max-width: 1100px) {
    .stat-grid, .mini-stats { grid-template-columns: 1fr 1fr; }
    .split, .fact-grid, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .menu-btn { display: inline-block; }
    .sidebar { position: fixed; transform: translateX(-105%); width: min(280px, 86vw); }
    .sidebar.open { transform: none; box-shadow: var(--shadow); }
    .sidebar-backdrop.show { display: block; }
    .content { padding: 12px 12px 32px; }
    .topbar { padding: 10px 12px; }
    .top-search { min-width: 0; flex: 1; }
    .topbar-user .meta { display: none; }
    .page-head h1 { font-size: 22px; }
    .cal-day { min-height: 72px; }
}
