:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #142033;
  --muted: #6b7586;
  --primary: #2463db;
  --primary-contrast: #ffffff;
  --accent: #188260;
  --border: #e3e8ef;
  --sidebar: #121b2a;
  --sidebar-text: #9da8b8;
  --sidebar-strong: #ffffff;
  --sidebar-active: #1c2a40;
  --warning: #9c3f18;
  --danger: #c63d4d;
  --shadow: 0 8px 24px rgba(25, 39, 62, .055);
}

html[data-theme="field"] {
  --bg: #f3efe7;
  --surface: #fffdf8;
  --surface-2: #f8f3e9;
  --text: #24332d;
  --muted: #6d746d;
  --primary: #a94820;
  --primary-contrast: #ffffff;
  --accent: #287358;
  --border: #e6ddce;
  --sidebar: #173d32;
  --sidebar-text: #cbdad3;
  --sidebar-strong: #fff8ea;
  --sidebar-active: #e5b94f;
  --warning: #b45e2e;
  --danger: #b94141;
  --shadow: 0 12px 32px rgba(49, 55, 45, .08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101621;
  --surface: #171f2d;
  --surface-2: #1c2636;
  --text: #f2f5f9;
  --muted: #98a5b8;
  --primary: #edae46;
  --primary-contrast: #151a23;
  --accent: #62cfa8;
  --border: #2a3547;
  --sidebar: #0a0f18;
  --sidebar-text: #909bac;
  --sidebar-strong: #ffffff;
  --sidebar-active: #263042;
  --warning: #f3a94a;
  --danger: #ff7885;
  --shadow: 0 14px 36px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { min-height: 100%; font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55; }
small { font-size: 16px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; box-shadow: 0 0 0 2px var(--surface); }
.skip-link { position: fixed; z-index: 100; top: 10px; left: 10px; padding: 10px 14px; border-radius: 8px; background: var(--primary); color: var(--primary-contrast); transform: translateY(-150%); }
.skip-link:focus { transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.block { display: block; color: var(--muted); margin-top: 3px; }

.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: 226px; display: flex; flex-direction: column; overflow-y: auto; padding: 27px 18px 20px; background: var(--sidebar); color: var(--sidebar-text); border: 0; }
.brand { display: grid; grid-template-columns: 42px 1fr; grid-template-rows: auto auto; column-gap: 11px; align-items: center; margin: 0 7px 34px; color: var(--sidebar-strong); }
.brand > span { grid-row: 1 / 3; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid color-mix(in srgb, var(--sidebar-text) 45%, transparent); border-radius: 9px; background: transparent; color: var(--sidebar-strong); font-weight: 900; letter-spacing: -.5px; }
.brand strong { font-size: 16px; letter-spacing: -.5px; }
.brand small { color: var(--sidebar-text); font-size: 11px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a, .sidebar nav button { position: relative; width: 100%; min-height: 44px; display: flex; gap: 12px; align-items: center; padding: 10px 13px; border: 0; border-radius: 8px; background: transparent; color: var(--sidebar-text); text-align: left; font-size: 16px; font-weight: 700; }
.sidebar nav a:hover, .sidebar nav button:hover { color: var(--sidebar-strong); background: color-mix(in srgb, var(--sidebar-active) 55%, transparent); }
.sidebar nav a.active { color: var(--sidebar-strong); background: var(--sidebar-active); }
.sidebar nav a.active::before { position: absolute; left: 0; width: 3px; height: 19px; border-radius: 3px; background: var(--primary); content: ""; }
html[data-theme="field"] .sidebar nav a.active { color: #173d32; }
.sidebar-bottom { margin-top: auto; }
.sidebar-bottom form { margin: 0; }
.workspace-shell { min-width: 0; margin-left: 226px; }
.workspace-topbar { display: flex; justify-content: space-between; align-items: center; height: 72px; padding: 0 clamp(28px, 4vw, 54px); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); }
.workspace-topbar time { color: var(--muted); font-size: 16px; }
.account-summary { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 750; }
.account-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 10%, var(--surface)); color: var(--primary); font-weight: 900; }
.main-shell { min-height: calc(100vh - 72px); margin: 0; padding: 34px clamp(28px, 4vw, 54px) 54px; animation: content-enter .24s ease-out both; }
.mobile-bar, .sidebar-overlay { display: none; }

.page-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin: 0 0 27px; }
.page-head.compact { align-items: center; }
.page-head h1 { margin: 2px 0 4px; font-size: clamp(28px, 3vw, 31px); line-height: 1.2; letter-spacing: -1.2px; }
.page-head p { margin: 0; color: var(--muted); font-size: 16px; }
.eyebrow { color: var(--primary) !important; font-size: 16px; font-weight: 900; letter-spacing: 1.2px; text-transform: uppercase; }
.actions, .button-row, .form-actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 44px; padding: 9px 15px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-weight: 800; }
.button:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); transform: translateY(-1px); }
.button.primary { border-color: var(--primary); background: var(--primary); color: var(--primary-contrast); }
.button.small { min-height: 44px; padding: 6px 10px; font-size: 16px; }
.button.danger { border-color: var(--danger); color: var(--danger); }
.text-button, .text-danger { padding: 4px; border: 0; background: none; color: var(--primary); font-weight: 750; }
.text-danger { color: var(--danger); }
:is(a, button).text-button, :is(a, button).text-danger { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; min-height: 128px; padding: 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.stat:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); transform: translateY(-1px); }
.stat span, .stat small { color: var(--muted); }
.stat strong { margin: 5px 0 3px; font-size: clamp(23px, 2vw, 31px); letter-spacing: -1px; }
.compact-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-stats .stat { min-height: 105px; }
.money-strip { display: grid; grid-template-columns: 1fr 1fr auto; align-items: center; margin: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.money-strip div { display: grid; gap: 3px; padding: 18px 20px; }
.money-strip div + div { border-left: 1px solid var(--border); }
.money-strip span { color: var(--muted); font-size: 16px; }
.money-strip a { padding: 18px 20px; color: var(--primary); font-size: 16px; font-weight: 850; }
.mail-status { display: flex; align-items: center; gap: 16px; margin: 0; padding: 18px 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); }
.mail-status strong { color: var(--text); }
.mail-status span:last-child { margin-left: auto; }
.dashboard-attention { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; padding: 11px 16px; border: 1px solid color-mix(in srgb, var(--warning) 26%, var(--border)); border-radius: 9px; background: color-mix(in srgb, var(--warning) 5%, var(--surface)); color: color-mix(in srgb, var(--warning) 78%, var(--text)); font-size: 16px; }
.dashboard-attention strong { color: var(--warning); }
.dashboard-attention a { display: inline-flex; align-items: center; min-height: 44px; margin-left: auto; color: var(--warning); font-weight: 850; }
.dashboard-attention a + a { margin-left: 0; }
.dashboard-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.dashboard-metric { position: relative; min-width: 0; padding: 19px 21px; }
.dashboard-metric + .dashboard-metric { border-left: 1px solid var(--border); }
.dashboard-metric:hover { background: color-mix(in srgb, var(--primary) 3%, var(--surface)); }
.dashboard-metric span, .dashboard-metric small { display: block; color: var(--muted); }
.dashboard-metric span { font-size: 16px; font-weight: 700; }
.dashboard-metric strong { display: block; margin: 5px 0 1px; overflow-wrap: anywhere; font-size: clamp(21px, 2vw, 25px); letter-spacing: -.8px; }
.dashboard-metric small { font-size: 16px; }
.dashboard-metric:last-child strong { color: var(--warning); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .65fr); gap: 14px; }
.dashboard-lower { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); gap: 14px; margin-top: 14px; }
.dashboard-lower.no-mail > .money-strip { grid-column: 1 / -1; }
.dashboard-lower > .panel { grid-column: 1 / -1; margin: 0; }
.span-2 { grid-column: 1 / -1; }
.panel { margin-bottom: 16px; padding: 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.panel h2 { margin: 0 0 16px; font-size: 17px; letter-spacing: -.35px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 15px; }
.section-head h2 { margin: 0; }
.section-head > a { display: inline-flex; align-items: center; min-height: 44px; color: var(--primary); font-weight: 800; }
.dashboard-projects, .dashboard-schedules { overflow: hidden; padding: 0; }
.dashboard-projects .section-head, .dashboard-schedules .section-head { margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dashboard-projects .section-head h2, .dashboard-schedules .section-head h2 { font-size: 16px; }
.dashboard-projects th:first-child, .dashboard-projects td:first-child { padding-left: 20px; }
.dashboard-projects td:first-child a { display: flex; align-items: center; min-height: 44px; }
.dashboard-projects th:last-child, .dashboard-projects td:last-child { padding-right: 20px; }
.dashboard-projects td:nth-child(3) { min-width: 170px; }
.dashboard-schedules > div:not(.section-head) { padding: 3px 20px 8px; }
.dashboard-schedules h3 { margin: 13px 0 2px; color: var(--muted); font-size: 16px; letter-spacing: .45px; }
.empty { padding: 22px !important; color: var(--muted); text-align: center; }
.activity, .trash-row { display: flex; justify-content: space-between; gap: 15px; padding: 11px 0; border-top: 1px solid var(--border); }
.activity:first-of-type, .trash-row:first-of-type { border-top: 0; }
.activity small, .trash-row small { display: block; color: var(--muted); }

.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: var(--surface-2); color: var(--muted); font-size: 16px; font-weight: 850; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--primary) 3%, transparent); }
td a:hover strong { color: var(--primary); }
.status { display: inline-flex; padding: 4px 7px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 16px; font-weight: 850; }
.status.pending, .status-estimate_sent, .status-contracted { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }
.kind-purchase { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.paid { color: var(--accent); }
.unpaid { color: var(--danger); }
.project-progress { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; width: 100%; margin-top: 8px; }
.project-progress-segment { height: 5px; border-radius: 4px; background: color-mix(in srgb, var(--border) 82%, var(--muted)); }
.project-progress[data-stage="measurement"] .project-progress-segment:nth-child(-n+1),
.project-progress[data-stage="estimate_sent"] .project-progress-segment:nth-child(-n+2),
.project-progress[data-stage="contracted"] .project-progress-segment:nth-child(-n+3),
.project-progress[data-stage="construction"] .project-progress-segment:nth-child(-n+4),
.project-progress[data-stage="completed"] .project-progress-segment:nth-child(-n+5),
.project-progress[data-stage="after_service"] .project-progress-segment:nth-child(-n+6) { background: color-mix(in srgb, var(--primary) 68%, var(--border)); }
.project-progress[data-stage="inquiry"] .project-progress-segment:nth-child(1),
.project-progress[data-stage="measurement"] .project-progress-segment:nth-child(2),
.project-progress[data-stage="estimate_sent"] .project-progress-segment:nth-child(3),
.project-progress[data-stage="contracted"] .project-progress-segment:nth-child(4),
.project-progress[data-stage="construction"] .project-progress-segment:nth-child(5),
.project-progress[data-stage="completed"] .project-progress-segment:nth-child(6),
.project-progress[data-stage="after_service"] .project-progress-segment:nth-child(7) { background: var(--warning); }

.filter-bar { display: flex; gap: 9px; align-items: center; margin-bottom: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.grow { flex: 1 1 260px; }
input, select, textarea { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: var(--surface); }
input[type="checkbox"] { width: 44px; min-height: 44px; }
.form-card { max-width: 980px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: grid; align-content: start; gap: 6px; }
.field label { font-size: 16px; font-weight: 850; }
.field label b { color: var(--danger); }
.field small { color: var(--muted); }
.field ul.errorlist, .form-errors { margin: 0; padding: 9px 12px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 11%, transparent); color: var(--danger); list-style: none; }
.form-actions { justify-content: flex-end; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
.detail-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.detail-list { margin: 0; }
.detail-list div { display: grid; grid-template-columns: 105px 1fr; gap: 15px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }
.preline { white-space: pre-line; }
.danger-zone { max-width: 980px; padding: 15px 4px; text-align: right; }
.notice { padding: 12px; border-radius: 9px; background: var(--surface-2); }
.notice.success { color: var(--accent); }
.notice.danger { color: var(--danger); }

.timeline-item { display: grid; grid-template-columns: 55px 1fr; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
.timeline-item time { color: var(--primary); font-weight: 900; }
.timeline-item small { display: block; color: var(--muted); }
.timeline-item.warning time { color: var(--warning); }
.calendar-panel { overflow-x: auto; }
.calendar-head { display: flex; justify-content: space-between; align-items: center; min-width: 720px; }
.calendar { min-width: 720px; display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays { padding: 10px 0; color: var(--muted); text-align: center; }
.calendar-day { min-height: 112px; padding: 8px; border-top: 1px solid var(--border); border-right: 1px solid var(--border); }
.calendar-day:nth-child(7) { border-right: 0; }
.calendar-day > time { display: grid; place-items: center; width: 26px; height: 26px; margin-bottom: 6px; font-size: 16px; font-weight: 850; }
.calendar-day.today > time { border-radius: 50%; background: var(--primary); color: var(--primary-contrast); }
.calendar-day.outside { opacity: .42; }
.calendar-event { display: block; margin: 4px 0; padding: 4px 6px; overflow: hidden; border-radius: 5px; background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-size: 16px; white-space: nowrap; text-overflow: ellipsis; }
.calendar-event span { font-weight: 850; }

.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-card { padding: 10px; border: 2px solid var(--border); border-radius: 11px; background: var(--surface); text-align: left; }
.theme-card i { display: block; height: 55px; margin-bottom: 8px; border-radius: 7px; }
.theme-card.field i { background: linear-gradient(135deg, #173d32 0 40%, #f3efe7 40% 74%, #a94820 74%); }
.theme-card.business i { background: linear-gradient(135deg, #ffffff 0 40%, #f3f6fa 40% 74%, #2463db 74%); border: 1px solid #e3e8ef; }
.theme-card.dark i { background: linear-gradient(135deg, #0a0f18 0 40%, #171f2d 40% 74%, #edae46 74%); }
.theme-card:hover { border-color: var(--primary); }
.messages { position: fixed; z-index: 60; top: 16px; right: 20px; max-width: min(420px, calc(100vw - 40px)); }
.message { padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.message.success { border-color: var(--accent); }
.message.error { border-color: var(--danger); }

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(circle at top left, color-mix(in srgb, var(--primary) 13%, transparent), transparent 45%), var(--bg); }
.auth-shell { width: min(100%, 430px); }
.auth-brand { display: flex; gap: 12px; align-items: center; justify-content: center; margin-bottom: 22px; }
.auth-brand span { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; background: var(--primary); color: var(--primary-contrast); font-weight: 900; }
.auth-brand strong { display: block; font-size: 18px; }
.auth-brand small { display: block; color: var(--muted); }
.auth-panel { padding: 30px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.auth-panel h1 { margin-top: 0; font-size: 27px; }
.auth-panel table { display: block; }
.auth-panel tbody, .auth-panel tr, .auth-panel th, .auth-panel td { display: block; padding: 0; border: 0; background: none; white-space: normal; }
.auth-panel th { margin-top: 13px; color: var(--text); }
.auth-panel td { margin-top: 6px; }
.auth-panel .btn { width: 100%; margin-top: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); font-weight: 800; }
.auth-panel .btn-primary { border-color: var(--primary); background: var(--primary); color: var(--primary-contrast); }
.auth-panel .float-right { display: block; margin-top: 13px; color: var(--muted); text-align: center; }

@keyframes content-enter {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .mobile-bar { position: sticky; top: 0; z-index: 35; display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 18px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); }
  .mobile-bar button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
  .sidebar { visibility: hidden; transform: translateX(-105%); transition: transform .2s ease; }
  .menu-open .sidebar { visibility: visible; transform: none; }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 39; border: 0; background: rgba(2, 8, 18, .5); }
  .menu-open .sidebar-overlay { display: block; }
  .workspace-shell { margin-left: 0; }
  .workspace-topbar { display: none; }
  .main-shell { margin-left: 0; padding: 26px 20px 50px; }
  .dashboard-grid, .detail-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-head .actions { width: 100%; }
  .page-head .actions .button, .page-head .actions form { flex: 1; }
  .page-head .actions form .button { width: 100%; }
  .stat-grid, .compact-stats { grid-template-columns: 1fr 1fr; }
  .dashboard-attention { align-items: flex-start; flex-wrap: wrap; }
  .dashboard-attention a, .dashboard-attention a + a { margin-left: 0; }
  .dashboard-metrics { grid-template-columns: 1fr 1fr; }
  .dashboard-metric:nth-child(3) { border-left: 0; }
  .dashboard-metric:nth-child(n+3) { border-top: 1px solid var(--border); }
  .dashboard-lower { grid-template-columns: 1fr; }
  .money-strip { grid-template-columns: 1fr 1fr; }
  .money-strip a { grid-column: 1 / -1; border-top: 1px solid var(--border); }
  .stat { min-height: 108px; padding: 15px; }
  .mail-status { align-items: flex-start; flex-direction: column; gap: 4px; }
  .mail-status span:last-child { margin-left: 0; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .theme-picker { grid-template-columns: 1fr; }
  .table-wrap table, .table-wrap tbody { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr { display: block; margin: 10px; padding: 8px 13px; border: 1px solid var(--border); border-radius: 11px; }
  .table-wrap td { display: grid; grid-template-columns: 100px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); white-space: normal; }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 16px; font-weight: 800; }
  .table-wrap td[colspan] { display: block; }
  .dashboard-projects td:nth-child(3) { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
