* {
    box-sizing: border-box;
}

:root {
    --charcoal: #262322;
    --charcoal-2: #3a332c;
    --accent: #f26522;
    --accent-dark: #d9531b;
    --accent-soft: #fdeae0;
    --ink: #1c1917;
    --muted: #6b6560;
    --line: #e7e2dd;
    --bg: #f7f5f2;
    --surface: #ffffff;
    --danger: #dc2626;
    --success: #16a34a;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
}

a {
    color: inherit;
}

/* ---------- app shell / topbar ---------- */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--charcoal);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 60px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}

.brand-logo-wrap {
    background: #fff;
    padding: 4px 10px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
}

.brand-logo {
    height: 18px;
    display: block;
}

.brand span {
    font-weight: 400;
    color: #b9b2ab;
    margin-left: 6px;
    font-size: 13px;
}

.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-links a {
    text-decoration: none;
    color: #d6d0c9;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
}

.nav-links a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-links a.active {
    background: var(--accent);
    color: #fff;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.user-name {
    font-weight: 600;
}

.role-badge {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #e8e3dd;
}

.role-badge.role-admin {
    background: #fff;
    color: var(--charcoal);
}

.user-box form {
    margin: 0;
}

.logout-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.content {
    flex: 1;
    padding: 28px clamp(16px, 4vw, 40px) 60px;
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- page head ---------- */

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.page-head h1 {
    margin: 0;
    font-size: 21px;
}

.page-sub {
    color: var(--muted);
    font-size: 13px;
}

/* ---------- KPI cards ---------- */

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
}

.kpi-label {
    font-size: 12.5px;
    color: var(--muted);
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.kpi-value.muted {
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
}

.progress-track {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 2px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
}

.progress-fill.over {
    background: var(--success);
}

/* ---------- charts ---------- */

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
}

.chart-card.wide {
    grid-column: 1 / -1;
}

.chart-card h2 {
    margin: 0 0 12px;
    font-size: 14px;
    color: #334155;
}

.chart-card canvas {
    max-height: 260px;
}

@media (max-width: 760px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------- tables ---------- */

.table-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
}

.table-card h2 {
    margin: 0 0 12px;
    font-size: 14px;
    color: #334155;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

td.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

td.empty {
    text-align: center;
    color: var(--muted);
    padding: 24px 0;
}

.check-col {
    width: 32px;
    text-align: center;
}

.row-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.row-actions a {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
}

.link-danger {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
}

.inline-form select {
    font-size: 12.5px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid var(--line);
}

/* ---------- stage badges ---------- */

.stage-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent);
}

.stage-badge[data-stage="협상중"] { background: #eeece9; color: #57534e; }
.stage-badge[data-stage="계약완료"] { background: #dbeafe; color: #1d4ed8; }
.stage-badge[data-stage="진행중"] { background: #ede9fe; color: #6d28d9; }
.stage-badge[data-stage="완료"] { background: #dcfce7; color: #15803d; }

/* ---------- forms ---------- */

.form-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
    max-width: 480px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
    margin-bottom: 22px;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stack-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.field-row {
    display: flex;
    gap: 14px;
}

.field-row label {
    flex: 1;
}

.field-hint {
    font-size: 12.5px;
    color: var(--muted);
    margin: -6px 0 16px;
}

.stack-form input,
.stack-form select {
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    color: var(--ink);
    font-family: inherit;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.primary-btn, .secondary-btn {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    display: inline-block;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
}

.primary-btn:hover {
    background: var(--accent-dark);
}

.secondary-btn {
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
}

.error {
    background: #fee2e2;
    color: var(--danger);
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 8px;
    margin: 0 0 14px;
}

/* ---------- file uploads ---------- */

.form-card-title {
    font-size: 15px;
    margin: 0 0 6px;
}

.upload-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.upload-form select {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13.5px;
}

.upload-form input[type="file"] {
    flex: 1;
    min-width: 160px;
    font-size: 13px;
    padding: 6px 0;
}

.upload-manual-fields {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-basis: 100%;
}

.upload-manual-fields input {
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
}

.upload-manual-fields input[type="number"] {
    flex: 1;
    min-width: 140px;
}

.upload-manual-fields .tilde {
    color: var(--muted);
    font-size: 13px;
}

.contract-picker {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 220px;
}

.contract-picker .contract-search {
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    border-bottom: none;
    font-size: 12.5px;
    font-family: inherit;
    background: var(--surface-2);
}

.contract-picker select {
    border-radius: 0 0 8px 8px;
}

.file-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13.5px;
}

.file-list li:last-child {
    border-bottom: none;
}

.file-list li.empty {
    color: var(--muted);
    padding: 16px 0;
}

.file-doc-type {
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 11.5px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.file-name {
    flex: 1;
    color: var(--ink);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-name:hover {
    color: var(--accent);
    text-decoration: underline;
}

.file-date {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.date-range {
    font-variant-numeric: tabular-nums;
}

/* ---------- filters ---------- */

.filter-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 18px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
}

.filter-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12.5px;
    color: var(--muted);
}

.filter-form input,
.filter-form select {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13.5px;
    font-family: inherit;
}

.active-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.active-filter a {
    color: inherit;
    text-decoration: underline;
    margin-left: auto;
    font-size: 12.5px;
}

/* ---------- 서류함 폴더 그룹 ---------- */

.doc-group {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, 0.04);
    margin-bottom: 16px;
    overflow: hidden;
}

.doc-group-head {
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.doc-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14.5px;
    font-weight: 600;
}

.doc-group-title a {
    color: var(--ink);
    text-decoration: none;
}

.doc-group-title a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.folder-icon {
    font-size: 15px;
}

.doc-group-count {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--accent-dark);
    background: var(--accent-soft);
    padding: 1px 8px;
    border-radius: 999px;
}

.doc-group-meta {
    font-size: 12.5px;
    color: var(--muted);
}

.doc-group .table-scroll table {
    margin: 0;
}

/* ---------- AI 문서대조 배지 ---------- */

.match-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: #eeece9;
    color: var(--muted);
    white-space: nowrap;
}

.match-badge.match-일치 { background: #dcfce7; color: #15803d; }
.match-badge.match-불일치_의심 { background: #fee2e2; color: #b91c1c; }
.match-badge.match-인식불가 { background: #f1f0ee; color: #78716c; }
.match-badge.match-미확인 { background: #f1f0ee; color: #a8a29e; }

.file-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.file-row:last-child {
    border-bottom: none;
}

.file-row-main {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
}

.file-match-note {
    margin: 0;
    font-size: 12px;
    color: #b91c1c;
    padding-left: 2px;
}

/* ---------- auth pages ---------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--charcoal) 0%, var(--charcoal-2) 100%);
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border-radius: 14px;
    padding: 32px 28px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.4);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: var(--charcoal);
    margin-bottom: 18px;
}

.auth-logo {
    height: 22px;
    display: block;
}

.auth-brand span {
    font-weight: 400;
    color: var(--muted);
    font-size: 13px;
    margin-left: 4px;
}

.auth-card h1 {
    font-size: 20px;
    margin: 0 0 16px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    color: var(--muted);
}

.auth-form input {
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
}

.auth-form button {
    margin-top: 4px;
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.auth-form button:hover {
    background: var(--accent-dark);
}

.auth-switch {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    margin: 16px 0 0;
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
}

.auth-note {
    text-align: center;
    font-size: 11.5px;
    color: #94a3b8;
    margin: 10px 0 0;
}
