/* =====================================================================
 * DAPER Design System
 * - Enterprise ERP tone: neutral surfaces, steel-blue accent, flat borders
 * - Mobile first behaviours for shell, grids, forms and modals
 * ===================================================================== */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --accent: #1d5bb8;
  --accent-strong: #16498f;
  --accent-soft: #eef4fc;
  --sidebar: #0e1a2b;
  --sidebar-2: #142338;
  --sidebar-text: #a9b8cc;
  --success: #0f8a5f;
  --danger: #c0392b;
  --warning: #b7791f;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-pop: 0 12px 32px rgba(15, 23, 42, .14);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.app-body,
body {
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  letter-spacing: -0.01em;
}

button, a, input, select, textarea {
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid rgba(29, 91, 184, .55);
  outline-offset: 1px;
}

/* ---------- Shell ---------- */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-sidebar {
  width: 248px;
  flex: 0 0 248px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: var(--sidebar-text);
  border-right: 1px solid rgba(255, 255, 255, .04);
}

.sidebar-brand {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.brand-mark {
  width: 28px;
  height: 29px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-mark.custom {
  width: 34px;
  flex-basis: 34px;
}

.brand-text {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.brand-tag {
  display: block;
  margin-top: 3px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .12em;
  color: #74869f;
  text-transform: uppercase;
}

.sidebar-company {
  margin: 12px 12px 4px;
  padding: 9px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid rgba(255, 255, 255, .06);
}

.sidebar-company p:first-child {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  color: #74869f;
  margin-bottom: 2px;
}

.sidebar-company p:last-child {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px 16px;
  overscroll-behavior: contain;
}

.sidebar-link,
.menu-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: 6px;
  border-left: 2px solid transparent;
  font-size: 13px;
  line-height: 1.35;
  color: var(--sidebar-text);
  text-align: left;
  transition: background .12s ease, color .12s ease;
}

.sidebar-link i,
.menu-toggle i {
  width: 17px;
  text-align: center;
  font-size: 12.5px;
  opacity: .85;
}

.sidebar-link:hover,
.menu-toggle:hover {
  background: rgba(255, 255, 255, .055);
  color: #fff;
}

.sidebar-link.active {
  background: rgba(52, 112, 190, .22);
  border-left: 2px solid #4f8fe0;
  color: #fff;
  font-weight: 600;
}

.menu-children {
  margin: 2px 0 8px 21px;
  padding-left: 4px;
  border-left: 1px solid rgba(255, 255, 255, .08);
}

.menu-children .sidebar-link {
  padding: 7px 10px 7px 12px;
  font-size: 12.5px;
}

.menu-children .sidebar-link i {
  font-size: 10px;
  width: 12px;
}

.menu-children .sidebar-link.active {
  background: rgba(52, 112, 190, .16);
  border-left-color: transparent;
}

.menu-group > .menu-children { display: none; }
.menu-group.open > .menu-children { display: block; }

.sidebar-footer {
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, .07);
  font-size: 11px;
  color: #74869f;
  line-height: 1.6;
}

.sidebar-footer .badge {
  background: rgba(255, 255, 255, .08);
  color: #c3d0e1;
  margin: 2px 2px 0 0;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(9, 15, 26, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Header ---------- */
.app-header {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.header-icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #526176;
  font-size: 15px;
  transition: background .12s ease, color .12s ease;
}

.header-icon-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.menu-btn { display: none; }

.app-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}

.app-breadcrumb span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-breadcrumb .sep {
  margin: 0 7px;
  color: #cbd5e1;
  font-size: 10px;
}

.app-breadcrumb .current {
  color: var(--text);
  font-weight: 600;
}

.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 380px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 80;
  overflow: hidden;
}

.notif-item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
}

.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: #f7f9fc; }
.notif-item.is-read { opacity: .62; }

.user-menu {
  position: relative;
  padding-left: 10px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
}

.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  border-radius: 6px;
  transition: background .12s ease;
}

.user-btn:hover { background: #f1f5f9; }

.user-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
}

.user-meta { text-align: left; line-height: 1.2; }
.user-meta .name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-meta .role { font-size: 11px; color: var(--muted); margin-top: 2px; }

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 80;
}

.user-menu-head {
  padding: 8px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid #eef2f7;
}

.user-menu-head .name { font-size: 13px; font-weight: 600; }
.user-menu-head .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.user-menu-panel button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: #334155;
  text-align: left;
}

.user-menu-panel button:hover { background: #f4f7fb; }
.user-menu-panel button.is-danger { color: #b42318; }
.user-menu-panel button.is-danger:hover { background: #fef3f2; }
.user-menu-panel button i { width: 14px; text-align: center; font-size: 12px; }

.page-content {
  flex: 1;
  overflow: auto;
  padding: 22px 24px 44px;
  scroll-behavior: smooth;
}

/* ---------- Page header ---------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-head-main {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
}

.page-head-main > div { min-width: 0; }

.page-head h1,
.page-head h2 {
  font-size: 19px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--text);
}

.page-head .sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.page-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ---------- Document editor ---------- */
.doc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.doc-head-main {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
}

.doc-head-text h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
}

.doc-head-text { min-width: 0; }

.doc-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.doc-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  word-break: keep-all;
}

.doc-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.doc-save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f8fafc;
  color: #5b6b80;
  font-size: 11.5px;
  white-space: nowrap;
}

.doc-save-state.is-saving {
  border-color: #f5e3b3;
  background: #fffaeb;
  color: #8a6d1d;
}

.doc-save-state.is-error {
  border-color: #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.doc-restore {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  padding: 9px 12px;
  border: 1px solid #cfe0f6;
  border-radius: 6px;
  background: #f4f8fe;
  color: #1d4f8f;
  font-size: 12.5px;
}

.doc-restore .btn { margin-left: auto; }

.doc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.doc-main {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.doc-section { overflow: hidden; }

.doc-section-head {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.doc-step {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  flex: 0 0 23px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11.5px;
  font-weight: 700;
}

.doc-section-title h2 {
  font-size: 14px;
  font-weight: 700;
}

.doc-section-title p {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.doc-section-head .btn {
  margin-left: auto;
  align-self: center;
}

.doc-section-body { padding: 18px; }

.doc-lines { overflow: auto; }
.doc-lines .erp-table th { background: #f8fafc; }

.doc-side { position: sticky; top: 0; }

.doc-summary { padding: 16px; }

.doc-summary-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: #526176;
  letter-spacing: .02em;
}

.doc-summary-list { padding: 8px 0 4px; }

.doc-summary-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 12.5px;
}

.doc-summary-list dt {
  flex: 0 0 auto;
  color: var(--muted);
}

.doc-summary-list dd {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

.doc-summary-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.doc-summary-total span { font-size: 12.5px; color: var(--muted); }

.doc-summary-total b {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.doc-summary-note {
  margin-top: 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.doc-mobile-actions { display: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card > .erp-table {
  border-radius: 0 0 var(--radius) var(--radius);
}

.card:has(> .erp-table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.kpi-card {
  position: relative;
  overflow: hidden;
}

.kpi-card i.bg-icon {
  position: absolute;
  right: 14px;
  top: 14px;
  bottom: auto;
  font-size: 20px;
  opacity: .18;
}

.kpi-card p:nth-of-type(2) {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ---------- Org chart ---------- */
.org-panel {
  margin-bottom: 16px;
  overflow: hidden;
}

.org-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.org-panel-title h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.org-panel-title p {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.org-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.org-panel-body { padding: 14px 18px 18px; }

.org-tree {
  padding: 16px 18px 20px;
}

.org-node {
  position: relative;
}

.org-tree > .org-node + .org-node { margin-top: 12px; }

.org-dept {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.org-dept.is-root {
  border-color: #cfdcee;
  box-shadow: var(--shadow-sm);
}

.org-dept-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid #edf1f6;
  background: #fbfcfe;
}

.org-dept.is-root > .org-dept-head {
  border-bottom-color: #dbe7f6;
  background: var(--accent-soft);
}

.org-dept-icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #eef2f7;
  color: #475569;
  font-size: 13px;
}

.org-dept.is-root .org-dept-icon {
  background: var(--accent);
  color: #fff;
}

.org-dept-title {
  flex: 1;
  min-width: 0;
}

.org-dept-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.org-dept-name > .truncate { min-width: 0; }

.org-code {
  flex: 0 0 auto;
  padding: 1px 5px;
  border-radius: 4px;
  background: #e9eef5;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 600;
}

.org-dept-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.org-head {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #334155;
  font-weight: 600;
  white-space: nowrap;
}

.org-head i { color: #64748b; font-size: 11px; }

.org-head.is-missing { color: #b45309; }
.org-head.is-missing i { color: #d97706; }

.org-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  white-space: nowrap;
}

.org-count i { font-size: 10.5px; }

.org-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  transition: background .12s ease, color .12s ease;
}

.org-toggle:hover {
  background: #eef2f7;
  color: var(--text);
}

.org-toggle i { transition: transform .15s ease; }

.org-node.is-collapsed > .org-dept > .org-dept-head { border-bottom: 0; }
.org-node.is-collapsed > .org-dept .org-toggle i { transform: rotate(-90deg); }
.org-node.is-collapsed > .org-dept > .org-dept-body,
.org-node.is-collapsed > .org-children { display: none; }

.org-dept-body { padding: 10px 12px 12px; }

.org-emps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
}

.org-emp {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid #edf1f6;
  border-radius: 6px;
  background: #fff;
}

.org-emp.is-head {
  border-color: #cfdcee;
  background: #f8fbff;
}

.org-emp.is-leave { opacity: .72; }

.org-avatar {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e8edf4;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
}

.org-emp.is-head .org-avatar {
  background: var(--accent);
  color: #fff;
}

.org-emp-body { flex: 1; min-width: 0; }

.org-emp-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.org-emp-name {
  overflow: hidden;
  min-width: 0;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-tag {
  flex: 0 0 auto;
  padding: 1px 4px;
  border-radius: 3px;
  background: #e6effb;
  color: var(--accent-strong);
  font-size: 9.5px;
  font-weight: 700;
}

.org-emp-meta {
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-emp-no { color: var(--muted-2); }

.org-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 0;
  color: var(--muted-2);
  font-size: 11.5px;
}

.org-children {
  margin: 10px 0 0 22px;
  padding-left: 22px;
  border-left: 1px solid var(--border-strong);
}

.org-children > .org-node {
  position: relative;
  margin-top: 10px;
}

.org-children > .org-node::before {
  content: '';
  position: absolute;
  top: 26px;
  left: -23px;
  width: 22px;
  border-top: 1px solid var(--border-strong);
}

.org-empty-state {
  padding: 44px 20px;
  text-align: center;
}

.org-empty-state > i {
  color: var(--muted-2);
  font-size: 28px;
}

.org-empty-state h2 {
  margin-top: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.org-empty-state p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
}

.org-empty-state .btn { margin-top: 14px; }

/* ---------- Tables ---------- */
.erp-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.erp-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 600;
  color: #526176;
  text-align: left;
  white-space: nowrap;
  letter-spacing: .01em;
}

.erp-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #edf1f6;
  font-size: 13px;
  color: #334155;
  white-space: nowrap;
}

.erp-table tbody tr:last-child td { border-bottom: 0; }
.erp-table tbody tr:hover { background: #f7f9fc; }
.erp-table tbody tr.clickable { cursor: pointer; }

/* ---------- Forms ---------- */
.erp-input {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}

.erp-input:hover { border-color: #b6c2d2; }

.erp-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 91, 184, .13);
}

.erp-input::placeholder { color: #9aa8ba; }

.erp-input[readonly],
.erp-input:disabled {
  background: #f8fafc;
  color: #65758b;
}

textarea.erp-input {
  min-height: 76px;
  resize: vertical;
  line-height: 1.55;
}

select.erp-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

input[type="checkbox"].erp-input { min-height: auto; }

label.erp-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

label.erp-label .req {
  color: #d92d20;
  margin-left: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 13px 16px;
}

.form-grid > * {
  grid-column: span var(--col, 6);
  min-width: 0;
}

.form-grid > .col-span-2 { grid-column: span 12; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.btn i { font-size: 12px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 1px rgba(15, 23, 42, .08);
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: #334155;
}
.btn-secondary:hover { background: #f5f8fc; border-color: #b6c2d2; }

.btn-danger {
  background: #fef3f2;
  border-color: #fecdca;
  color: #b42318;
}
.btn-danger:hover { background: #fee4e2; }

.btn-success {
  background: #077a52;
  color: #fff;
}
.btn-success:hover { background: #066244; }

.btn-warning {
  background: #b7791f;
  color: #fff;
}
.btn-warning:hover { background: #996215; }

.btn-sm {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: 5px;
}
.btn-sm i { font-size: 11px; }

.btn-lg {
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
  border-radius: 7px;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  vertical-align: middle;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(9, 15, 26, .52);
}

.modal-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 24px 60px -12px rgba(9, 15, 26, .45);
  animation: modal-in .16s ease-out;
  overflow: hidden;
}

@keyframes modal-in {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-head .close-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: #8996a8;
  font-size: 15px;
}
.modal-head .close-btn:hover { background: #f1f5f9; color: #0f172a; }

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

body.modal-open { overflow: hidden; }

/* ---------- Toast ---------- */
#toast-root { top: 68px !important; }

.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 220px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18);
  animation: slide .2s ease-out;
}

@keyframes slide {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Data grid toolbar ---------- */
.grid-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.grid-toolbar-left,
.grid-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.grid-toolbar-right { margin-left: auto; }

.grid-search-wrap { position: relative; }
.grid-search-wrap > i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--muted-2);
  pointer-events: none;
}

.grid-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.grid-filters .erp-input {
  width: auto;
  min-width: 120px;
}

.grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.grid-scroll.is-contained {
  overflow-y: auto;
}

/* 그리드 하나가 페이지 본문 전체인 경우: 카드가 남은 높이를 채우고 카드 안에서만 스크롤 */
@media (min-width: 1024px) {
  .page-content.page-fit {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 18px;
  }

  .page-content.page-fit > .page-head { flex: 0 0 auto; }

  .page-fit .grid-fit {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .page-fit .grid-fit > .card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .page-fit .grid-fit .grid-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
  }
}

.grid-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: #526176;
}

.grid-footer .pager {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ---------- Auth ---------- */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  background: #f6f8fb;
}

.auth-aside {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px 52px;
  background: var(--sidebar);
  color: #d9e3f0;
}

.auth-aside::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 30% 20%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 30% 20%, #000 0%, transparent 78%);
  pointer-events: none;
}

.auth-aside > * { position: relative; }

.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.auth-brand .brand-mark { width: 33px; height: 34px; flex-basis: 33px; }
.auth-brand .brand-text { font-size: 17px; }

.auth-pitch {
  max-width: 420px;
  margin: 32px 0;
}

.auth-pitch h2 {
  font-size: 27px;
  line-height: 1.42;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.auth-pitch p {
  margin-top: 12px;
  font-size: 13.5px;
  line-height: 1.65;
  color: #93a6bd;
}

.auth-features {
  margin-top: 28px;
  display: grid;
  gap: 12px;
}

.auth-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: #c3d0e1;
  line-height: 1.5;
}

.auth-features i {
  width: 16px;
  margin-top: 3px;
  color: #5d93d6;
  font-size: 12px;
  text-align: center;
}

.auth-note {
  font-size: 11.5px;
  color: #6c7f96;
  line-height: 1.7;
}

.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 28px;
}

.auth-card {
  width: 100%;
  max-width: 392px;
  padding: 30px 30px 26px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .04);
}

.auth-page-single { grid-template-columns: 1fr; }

.auth-brand.brand-on-light .brand-text { color: var(--text); }
.auth-brand.brand-on-light .brand-tag { color: #8594a8; }

.app-sidebar.is-platform .sidebar-link.active {
  background: rgba(148, 163, 184, .16);
  border-left-color: #94a3b8;
}

.auth-card-wide { max-width: 720px; }

.auth-head { margin-bottom: 22px; }
.auth-head h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.auth-head p { margin-top: 5px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }

.auth-mobile-brand {
  display: none;
  align-items: center;
  gap: 9px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.auth-mobile-brand .brand-text { color: var(--text); }

.auth-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #eef2f7;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.auth-foot a { color: var(--accent); font-weight: 600; }
.auth-foot a:hover { text-decoration: underline; }

.demo-box {
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid #e3eaf4;
  border-radius: 6px;
  background: #f7fafd;
  font-size: 11.5px;
  line-height: 1.65;
  color: #5b6b80;
}

.demo-box b { color: #334155; }

/* ---------- Misc ---------- */
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 48px 20px;
  color: var(--muted-2);
  font-size: 13px;
  text-align: center;
}

.empty-state i { font-size: 26px; margin-bottom: 4px; opacity: .7; }

/* WMS map */
.wms-canvas { background: #f8fafc; background-image: linear-gradient(#e2e8f0 1px, transparent 1px), linear-gradient(90deg, #e2e8f0 1px, transparent 1px); border: 1px solid var(--border-strong); border-radius: 6px; position: relative; overflow: auto; user-select: none; }
.wms-zone { position: absolute; border-radius: 6px; border: 2px solid; box-sizing: border-box; }
.wms-zone .zone-title { position: absolute; top: 2px; left: 6px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); pointer-events: none; }
.wms-zone.editable { cursor: move; }
.wms-zone .resize-handle { position: absolute; right: -4px; bottom: -4px; width: 12px; height: 12px; background: #fff; border: 2px solid #475569; border-radius: 3px; cursor: nwse-resize; }
.wms-loc { position: absolute; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); font-size: 9px; font-weight: 600; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 2px; cursor: pointer; transition: transform .1s; box-sizing: border-box; overflow: hidden; }
.wms-loc:hover { transform: scale(1.08); z-index: 5; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.wms-loc.selected { outline: 3px solid #1e293b; z-index: 6; }
.wms-loc .fill { position: absolute; left: 0; right: 0; bottom: 0; opacity: .85; }
.wms-loc .lbl { position: relative; z-index: 1; color: #0f172a; }
.wms-tooltip { position: fixed; z-index: 95; background: #0f172a; color: #fff; font-size: 12px; padding: 8px 10px; border-radius: 6px; pointer-events: none; max-width: 260px; box-shadow: 0 4px 12px rgba(0,0,0,.3); }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #b0bdcd; background-clip: padding-box; }

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .doc-grid { grid-template-columns: minmax(0, 1fr); }
  .doc-side { position: static; order: 2; }
  .doc-main { order: 1; }
}

@media (max-width: 1023px) {
  body.nav-open { overflow: hidden; }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: 264px;
    flex-basis: 264px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(9, 15, 26, .25);
  }

  .app-sidebar.open { transform: none; }

  .menu-btn { display: inline-flex; }

  .page-content { padding: 16px 16px 36px; }

  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-main { padding: 24px 16px; }
  .auth-mobile-brand { display: flex; }
  .auth-card { padding: 24px 20px 20px; }
}

@media (max-width: 767px) {
  .app-header {
    height: 52px;
    flex-basis: 52px;
    padding: 0 10px;
    gap: 6px;
  }

  .user-meta, .user-btn > .fa-chevron-down { display: none; }
  .user-menu { padding-left: 6px; }
  .app-breadcrumb { font-size: 12.5px; }
  .app-breadcrumb .crumb-parent { display: none; }
  .app-breadcrumb .sep { display: none; }

  .page-content { padding: 13px 12px calc(28px + env(safe-area-inset-bottom)); }

  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 12px; }
  .page-head h1, .page-head h2 { font-size: 17px; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 0 0 auto; }

  .doc-head { gap: 10px; margin-bottom: 10px; }
  .doc-head-text h1 { font-size: 18px; }
  .doc-head-actions { width: 100%; }
  .doc-head-actions .btn { display: none; }
  .doc-head-actions .doc-save-state { width: 100%; justify-content: center; }
  .doc-restore { align-items: flex-start; flex-wrap: wrap; font-size: 11.5px; }
  .doc-restore .btn { margin-left: 0; }
  .doc-grid { gap: 12px; }
  .doc-main { gap: 12px; }
  .doc-section-head { padding: 12px 14px; }
  .doc-section-body { padding: 14px; }
  .doc-lines { margin: 0; }
  .doc-side .doc-summary { padding: 14px; }
  .doc-mobile-actions {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    gap: 8px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .08);
  }
  .doc-mobile-actions .btn { flex: 1; height: 40px; }
  .page-content.doc-editor-page { padding-bottom: 82px; }

  .form-grid { grid-template-columns: 1fr; gap: 11px; }
  .form-grid > * { grid-column: 1 / -1; }
  .form-grid > .col-span-2 { grid-column: 1 / -1; }

  .erp-input { font-size: 16px; min-height: 38px; }
  select.erp-input { min-height: 38px; }
  textarea.erp-input { font-size: 16px; }
  .btn { height: 36px; }
  .btn-sm { height: 30px; padding: 0 10px; }
  .header-icon-btn { width: 36px; height: 36px; }

  .erp-table th { padding: 8px 10px; font-size: 11px; }
  .erp-table td { padding: 8px 10px; font-size: 12.5px; }

  .grid-toolbar { padding: 8px; gap: 6px; }
  .grid-toolbar-left, .grid-toolbar-right { width: 100%; }
  .grid-toolbar-right { margin-left: 0; }
  .grid-search-wrap { flex: 1 1 100%; }
  .grid-search-wrap input.grid-search { width: 100%; }
  .grid-filters { width: 100%; }
  .grid-filters .erp-input { flex: 0 1 auto; min-width: 140px; }
  .grid-footer { flex-wrap: wrap; justify-content: center; font-size: 12px; }

  .kpi-card { padding: 12px !important; }
  .kpi-card p:nth-of-type(2) {
    font-size: clamp(16px, 4.6vw, 20px);
    line-height: 1.3;
    letter-spacing: -0.02em;
    white-space: nowrap;
  }
  .kpi-card i.bg-icon { top: 10px; right: 10px; font-size: 16px; }

  .org-panel-head {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }
  .org-panel-actions { width: 100%; }
  .org-panel-actions .btn { flex: 1; }
  .org-panel-body { padding: 12px; }
  .org-tree { padding: 12px; }
  .org-dept-head { gap: 8px; padding: 10px 11px; }
  .org-dept-body { padding: 9px 10px 10px; }
  .org-dept-name { font-size: 13px; }
  .org-dept-meta { gap: 8px; }
  .org-emps { grid-template-columns: 1fr; }
  .org-children {
    margin-left: 10px;
    padding-left: 14px;
  }
  .org-children > .org-node::before {
    top: 24px;
    left: -15px;
    width: 14px;
  }
  .org-empty-state { padding: 34px 16px; }

  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal-box {
    max-height: 100vh;
    max-height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: none !important;
    border-radius: 0;
    animation: none;
  }
  .modal-head { padding: 11px 14px; padding-top: calc(11px + env(safe-area-inset-top)); }
  .modal-body { padding: 14px; }
  .modal-foot {
    padding: 10px 14px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
  }
  .modal-foot .btn { flex: 1; }

  .modal-box[data-dialog="compact"] {
    height: auto;
    min-height: 0;
    max-height: 88dvh;
    max-width: calc(100vw - 28px) !important;
    align-self: center;
    margin: auto;
    border-radius: 10px;
  }
  .modal-box[data-dialog="compact"] .modal-head { padding-top: 11px; }
  .modal-box[data-dialog="compact"] .modal-foot { padding-bottom: 10px; }
  .modal-box[data-dialog="compact"] .modal-foot .btn { flex: 0 0 auto; }

  .notif-panel {
    position: fixed;
    top: 58px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: calc(100dvh - 70px);
  }

  #toast-root {
    top: 60px !important;
    bottom: auto !important;
    left: 10px !important;
    right: 10px !important;
  }
  #toast-root .toast {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .auth-main { padding: 16px 14px; align-items: flex-start; }
  .auth-card { max-width: none; margin-top: 4px; padding: 22px 18px 18px; }
  .auth-head h1 { font-size: 18px; }
}

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

@media print {
  aside, header, .no-print { display: none !important; }
  .app-sidebar, .app-header, .sidebar-overlay { display: none !important; }
  .page-content { overflow: visible; padding: 0; }
  .card { box-shadow: none; border-color: #d5dbe4; }
  body { background: #fff; }
  .org-toggle, .org-panel-actions { display: none !important; }
  .org-node.is-collapsed > .org-dept > .org-dept-body,
  .org-node.is-collapsed > .org-children { display: block !important; }
  .org-dept { break-inside: avoid; }
}
