:root {
  --bg: #f6f4ee;
  --bg-accent: #efeae0;
  --surface: #ffffff;
  --surface-soft: #faf8f4;
  --surface-hover: #f5f2ea;
  --sidebar: #11231b;
  --sidebar-elevated: #183025;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #f3efe6;
  --sidebar-muted: #94a89d;
  --accent: #184231;
  --accent-hover: #215741;
  --accent-soft: #eaf3ee;
  --gold: #c69752;
  --gold-soft: rgba(198, 151, 82, 0.16);
  --ink: #1a211d;
  --ink-secondary: #4a5750;
  --muted: #6e7a73;
  --line: #e5e0d5;
  --line-strong: #d3cbbd;
  --danger: #b93838;
  --danger-soft: #fdf1f1;
  --danger-line: #f3cccc;
  --warn-bg: #fdf8ec;
  --warn-line: #eedbb4;
  --warn-ink: #7d5314;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(17, 35, 27, 0.04);
  --shadow-md: 0 4px 16px -4px rgba(17, 35, 27, 0.07), 0 1px 3px rgba(17, 35, 27, 0.04);
  --shadow-lg: 0 20px 45px -12px rgba(17, 35, 27, 0.22);
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

/* Sidebar */
aside {
  background:
    radial-gradient(circle at 15% 0%, rgba(198, 151, 82, 0.14), transparent 42%),
    linear-gradient(180deg, #13281f 0%, #0e1d16 100%);
  color: var(--sidebar-text);
  padding: 24px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(0, 0, 0, 0.15);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 14px;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #c69752 0%, #9e7335 100%);
  color: #102018;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(198, 151, 82, 0.28);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
}

.brand small {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  margin-top: 3px;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

nav a,
nav details summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #cdd8d1;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.12s ease;
  list-style: none;
  user-select: none;
}

nav details summary::-webkit-details-marker {
  display: none;
}

nav details summary::after {
  content: '';
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.18s ease;
  opacity: 0.7;
}

nav details[open] summary::after {
  transform: rotate(225deg);
}

nav a svg,
nav details summary svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.82;
}

nav a:hover,
nav details summary:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

nav a.active {
  background: linear-gradient(90deg, rgba(198, 151, 82, 0.22) 0%, rgba(198, 151, 82, 0.08) 100%);
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--gold);
}

nav a.active svg {
  color: var(--gold);
  opacity: 1;
}

nav details {
  display: flex;
  flex-direction: column;
}

nav details[open] {
  background: rgba(0, 0, 0, 0.14);
  border-radius: 10px;
  padding-bottom: 6px;
}

nav details a {
  padding: 8px 12px 8px 38px;
  font-size: 13px;
  color: #b7c6bd;
}

nav details a.startup-subnav {
  padding-left: 46px;
  font-size: 12.5px;
  color: #9eb1a6;
}

.aside-note {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sidebar-border);
  font-size: 12.5px;
  line-height: 1.5;
  color: #d6dfd9;
}

.aside-note small {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--gold);
  font-size: 11.5px;
  font-weight: 500;
}

.aside-note small::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(198, 151, 82, 0.2);
}

/* Main Workspace */
main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 26px 34px 32px;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 6px;
}

h1#page-title {
  margin: 0;
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.025em;
  color: var(--ink);
}

header label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 7px 12px 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
  box-shadow: var(--shadow-sm);
}

header label[hidden] {
  display: none;
}

header input[type="month"] {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Status Toast / Banner */
#status:empty {
  display: none;
}

#status {
  margin-bottom: 16px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  background: var(--sidebar);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  animation: slideDown 0.2s ease;
}

#status::before {
  content: '●';
  color: var(--gold);
  font-size: 10px;
}

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

/* View & Panels */
#view {
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-md);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel h3 {
  margin: 14px 0 8px;
  font-size: 14.5px;
  font-weight: 700;
}

.panel p {
  margin: 0 0 12px;
  color: var(--ink-secondary);
}

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-ink);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.notice::before {
  content: 'i';
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(146, 88, 14, 0.14);
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
  margin-top: 1px;
}

/* KPI Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}

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

.card strong {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.025em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.card small {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.card.highlight {
  background: linear-gradient(135deg, #132c22 0%, #1d4233 100%);
  border-color: rgba(198, 151, 82, 0.45);
  color: #ffffff;
  box-shadow: 0 10px 24px -8px rgba(17, 35, 27, 0.35);
}

.card.highlight .label {
  color: #e4c087;
}

.card.highlight strong {
  color: #ffffff;
}

.card.highlight small {
  color: #b8c9bf;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

/* Buttons & Actions */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

button,
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: #bfb5a4;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary,
button.quick-sales {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(24, 66, 49, 0.22);
}

button.primary:hover:not(:disabled),
button.quick-sales:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.danger {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}

button.danger:hover:not(:disabled) {
  background: #fbe3e3;
  border-color: #e6aaaa;
}

.quick-actions button {
  padding: 10px 16px;
  border-radius: 11px;
  font-size: 13.5px;
}

/* Toolbar & Inputs */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.toolbar input#search {
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 66, 49, 0.12);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
}

label.inline-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--ink);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Bars Chart */
.bar-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 98px;
  gap: 12px;
  align-items: center;
  padding: 7px 0;
  font-size: 13px;
}

.bar-row > span:first-child {
  font-weight: 600;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-row > span:last-child {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.track {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.bar {
  height: 100%;
  background: linear-gradient(90deg, #1b4b37 0%, #3a8062 100%);
  border-radius: 999px;
  min-width: 3px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--surface);
}

thead th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--surface-hover);
}

tbody td button {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
  margin-right: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg);
  color: var(--ink-secondary);
  border: 1px solid var(--line);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(24, 66, 49, 0.16);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-color: var(--warn-line);
}

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
  background: var(--surface-soft);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
}

/* Forms & Formulas */
form.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

form.panel button[type="submit"] {
  align-self: flex-start;
}

.formula {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

.formula p {
  margin: 0 0 8px;
}

details.panel summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

details.panel summary::-webkit-details-marker {
  display: none;
}

details.panel summary::after {
  content: '열기 / 접기';
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
}

details.panel[open] summary {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.simulation {
  max-width: 240px;
}

/* Footer */
footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* Dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(640px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(14, 29, 22, 0.55);
  backdrop-filter: blur(4px);
}

#edit-form,
#confirm-form {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
}

#close {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  font-size: 14px;
}

#fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#form-error,
#startup-entry-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

#form-error:empty,
#startup-entry-error:empty {
  display: none;
}

.recipe-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 38px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.recipe-line button[data-remove-line] {
  padding: 0;
  height: 38px;
  color: var(--danger);
}

.sales-upload-note {
  display: block;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.sales-upload-note[hidden] {
  display: none;
}

#sales-upload,
#menu-upload {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line-strong);
}

#sales-upload[hidden],
#menu-upload[hidden] {
  display: none;
}

#confirm-dialog {
  width: min(440px, calc(100vw - 28px));
}

#confirm-message {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-secondary);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

/* Mobile Responsive */
@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: static;
    height: auto;
    padding: 16px;
    gap: 12px;
  }

  nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  nav a,
  nav details summary {
    padding: 8px 11px;
    font-size: 12.5px;
  }

  nav details[open] {
    width: 100%;
  }

  .aside-note {
    display: none;
  }

  main {
    padding: 18px 16px 28px;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .table-wrap {
    border: none;
  }

  table, thead, tbody, th, td, tr {
    display: block;
  }

  thead {
    display: none;
  }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    padding: 8px 12px;
    background: var(--surface);
  }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    text-align: right;
  }

  tbody td:last-child {
    border-bottom: none;
  }

  tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 12px;
    color: var(--muted);
    text-align: left;
  }
}
.mobile-nav { display: none; }

@media (max-width: 640px) {
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    margin: 0;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--surface, white);
    border-top: 1px solid var(--line);
  }
  .mobile-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 4px;
    color: var(--ink, #202e27);
  }
  .mobile-nav a.active { background: #173c2d; color: white; }
  body:has(#page-title) .panel > .quick-actions button { min-height: 48px; }
  #editor button[type="submit"] { min-height: 48px; width: 100%; }
}
