:root {
    --primary: #1D4ED8;
    --primary-dark: #1E40AF;
    --navy: #0F172A;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --border: #E2E8F0;
    --text: #1E293B;
    --muted: #64748B;
    --ok: #059669;
    --warn: #D97706;
    --danger: #DC2626;
    --stamp: #B91C1C;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --field-radius: 8px;
    --primary-soft: #EFF6FF;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: "Pretendard", "Noto Sans KR", sans-serif; color: var(--text); background: var(--bg); overflow-x: hidden; }
button, a { font: inherit; }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; }

.field-label { display: block; margin-bottom: 6px; font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.field-hint { display: block; margin: 6px 0 0; font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.pw-match { display: block; margin: 6px 0 0; font-size: 0.78rem; font-weight: 800; color: var(--danger); }
.pw-match.is-ok { color: var(--ok); }
.field-input,
input.field-input,
select.field-input,
textarea.field-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--field-radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
}
.field-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}
textarea.field-input { min-height: 88px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-weight: 700;
    background: #fff;
    color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--primary-soft); border-color: #BFDBFE; color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 0.8rem; }
.btn-menu {
    width: 40px; height: 40px; padding: 0; flex: 0 0 40px;
    background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn-menu:hover, .btn-menu[aria-expanded="true"] { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-menu svg { width: 22px; height: 22px; display: block; }
.form-error { color: var(--danger); font-weight: 700; margin: 8px 0 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-bg {
    position: fixed; inset: 0;
    background: linear-gradient(160deg, #0F172A 0%, #1E3A8A 50%, #93C5FD 140%);
    z-index: 0;
}
.login-card {
    position: relative; z-index: 1;
    width: min(100%, 420px);
    background: #fff;
    border-radius: 20px;
    padding: 28px 24px 24px;
    box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand h1 { margin: 10px 0 0; font-size: 1.25rem; }
.login-sub { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.login-form { display: grid; gap: 12px; }

.app-shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 216px;
    background: var(--navy); color: #fff;
    display: flex; flex-direction: column;
    padding: 12px 8px 10px; overflow: hidden; z-index: 50;
}
.sidebar-brand { display: flex; gap: 8px; align-items: center; padding: 2px 8px 10px; flex: 0 0 auto; }
.sidebar-brand img { width: 28px; height: 28px; flex: 0 0 auto; }
.sidebar-brand__who { min-width: 0; }
.sidebar-brand__name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sidebar-brand strong { font-size: 0.9rem; line-height: 1.25; }
.role-badge {
    display: inline-flex; align-items: center;
    height: 18px; padding: 0 7px; border-radius: 999px;
    font-size: 0.68rem; font-weight: 700; line-height: 1;
    color: #1E3A8A; background: #BFDBFE; white-space: nowrap;
}
.sidebar-brand__co { display: block; margin-top: 2px; font-size: 0.7rem; color: #93C5FD; font-weight: 600; line-height: 1.3; }
.side-nav { display: grid; gap: 1px; flex: 1 1 auto; min-height: 0; overflow: hidden; align-content: start; }
.side-nav a, .side-nav button {
    display: flex; align-items: center; gap: 8px; text-align: left; width: 100%;
    color: #e2e8f0; background: transparent; border: 0;
    padding: 5px 10px; min-height: 32px; line-height: 1.2;
    border-radius: 8px; font-size: 0.8125rem; font-weight: 650;
}
.side-nav a:hover, .side-nav button:hover { background: rgba(147, 197, 253, .14); }
.side-nav a.is-active, .side-nav button.is-active { background: rgba(147, 197, 253, .22); color: #dbeafe; }
.nav-ico { display: inline-flex; width: 16px; height: 16px; flex: 0 0 16px; opacity: .92; }
.nav-ico svg { width: 16px; height: 16px; display: block; }
.sidebar-foot {
    display: grid; gap: 4px; flex: 0 0 auto; margin-top: 8px; padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-foot .btn {
    color: #fff; background: transparent; border-color: rgba(255,255,255,.2);
    height: 32px; font-size: 0.8rem; font-weight: 650; justify-content: flex-start; padding: 0 10px;
}
.sidebar-foot .btn:hover { background: rgba(147, 197, 253, .14); color: #fff; border-color: #93C5FD; }
.app-main { display: flex; flex-direction: column; min-width: 0; grid-column: 2; }
.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.1rem; flex: 1; }
.topbar-user { color: var(--muted); font-weight: 700; }
.content { padding: 20px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card, .panel {
    background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-card { padding: 16px; }
.stat-card b { display: block; font-size: 1.35rem; margin-top: 6px; }
.stat-card span { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.panel { padding: 16px; }
.notice {
    margin: 0 0 16px; padding: 12px 14px;
    border-radius: 10px; background: #FFF7ED; color: #9A3412;
    border: 1px solid #FED7AA; font-size: 0.85rem; line-height: 1.45;
}
.notice.is-ok { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar .grow { flex: 1; min-width: 180px; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { background: #EFF6FF; font-size: 0.78rem; color: var(--primary-dark); }
table.data tbody tr:hover td { background: #F8FAFC; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.badge {
    display: inline-flex; align-items: center;
    height: 24px; padding: 0 8px; border-radius: 999px;
    font-size: 0.75rem; font-weight: 800; background: #F1F5F9; color: #334155;
}
.badge-issued { background: #DCFCE7; color: #166534; }
.badge-cancelled { background: #FEE2E2; color: #991B1B; }
.badge-draft { background: #E0F2FE; color: #075985; }
.badge-none { background: #FEF3C7; color: #92400E; }
.badge-sent { background: #DBEAFE; color: #1E40AF; }
.badge-rejected { background: #FEE2E2; color: #991B1B; }
.badge-ours { background: #DBEAFE; color: #1E40AF; }
.badge-partner { background: #F1F5F9; color: #334155; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.8rem; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.panel.form-grid { max-width: 920px; }
.zip-row { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; }
.zip-row .field-input { width: 7.5rem; flex: 0 0 7.5rem; min-width: 0; }
.zip-row .btn { flex: 0 0 auto; white-space: nowrap; height: 40px; }

.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.party-pick { position: relative; }
.party-pick__selected {
    margin-top: 8px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px; background: #F8FAFC;
    min-height: 64px;
}
.party-pick__selected strong { display: block; }
.party-pick__selected span { color: var(--muted); font-size: 0.8rem; }
.party-pick__list {
    position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
    margin-top: 4px; max-height: 240px; overflow: auto;
    background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.party-pick__list button {
    display: block; width: 100%; text-align: left;
    padding: 10px 12px; border: 0; background: #fff; border-bottom: 1px solid var(--border);
}
.party-pick__list button:hover { background: var(--primary-soft); }
.party-pick__list button small { display: block; color: var(--muted); font-weight: 500; }
.amount-box {
    display: grid; grid-template-columns: 160px 1fr 1fr 1fr; gap: 12px; align-items: end;
}
.amount-read { padding: 10px 12px; border-radius: 8px; background: #F8FAFC; border: 1px solid var(--border); font-weight: 800; }
.items-table input { min-width: 0; }
.items-table td { padding: 6px; }

.modal {
    position: fixed; inset: 0; z-index: 100;
    display: none; align-items: center; justify-content: center;
    padding: 16px; background: rgba(15, 23, 42, .45);
}
.modal.is-open { display: flex; }
.modal-panel { width: min(100%, 720px); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; }
.modal-panel.modal-sm { width: min(100%, 420px); }
.modal-panel.modal-company { width: min(100%, 920px); display: flex; flex-direction: column; overflow: hidden; position: relative; }
.modal-panel.modal-post { width: 95%; max-width: 95%; }
.co-post-dim {
    position: absolute; inset: 0; z-index: 5;
    display: flex; align-items: center; justify-content: center;
    background: rgba(15, 23, 42, .45); border-radius: 16px;
}
.co-post-dim .modal-post { width: 95%; max-width: 95%; max-height: 92%; overflow: auto; }
.modal-company .modal-body { overflow: auto; flex: 1; min-height: 0; }
.modal-head, .modal-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px;
}
.modal-head { background: var(--navy); color: #fff; }
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-head .btn { color: #fff; border-color: rgba(255,255,255,.25); background: transparent; }
.modal-body { padding: 16px; }
.modal-foot { border-top: 1px solid var(--border); justify-content: flex-end; }

.invoice-view { display: grid; gap: 12px; max-width: 920px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 0.9rem; }
.kv b { color: var(--muted); font-weight: 700; }

.sidebar-backdrop { display: none; }
.mobile-only { display: none; }

@media (max-width: 900px) {
    .form-grid, .party-grid, .amount-box { grid-template-columns: 1fr; }
    .app-shell { display: block; grid-template-columns: none; width: 100%; max-width: 100%; }
    .app-main { grid-column: auto; width: 100%; max-width: 100%; min-width: 0; min-height: 100vh; }
    .content { padding: 14px 12px; }
    .topbar { padding: 12px; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(260px, 86vw); height: 100%;
        transform: translateX(-105%); transition: transform .2s; z-index: 70; pointer-events: none;
    }
    .sidebar.is-open { transform: none; pointer-events: auto; }
    .sidebar-backdrop.is-open {
        display: block !important; position: fixed; inset: 0;
        background: rgba(15, 23, 42, .4); z-index: 60; cursor: pointer;
    }
    .mobile-only { display: inline-flex; }
    .toolbar .grow { min-width: 0; }
}
