:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-subtle: #eef3ee;
  --ink: #1d2520;
  --muted: #657169;
  --line: #d9dfda;
  --accent: #2e765e;
  --accent-strong: #225b49;
  --warn: #9a6416;
  --danger: #b23832;
  --danger-bg: #fff1ef;
  --focus: #2b6ed3;
  --shadow: 0 8px 24px rgba(26, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid #b9c9bd;
  border-radius: 8px;
  background: #e7f1e9;
  color: var(--accent-strong);
  font-weight: 800;
}

.brand-title {
  font-size: 16px;
  font-weight: 750;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--surface-subtle);
  color: var(--ink);
}

.main {
  width: min(1200px, 100%);
  padding: 28px 32px 48px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  font-weight: 730;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.topbar-actions,
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.link-button,
.back-button {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border-color: #b8c7bc;
  background: #edf4ef;
  color: var(--accent-strong);
}

.ghost-button,
.back-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.link-button {
  min-height: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 0;
}

.danger-button {
  background: var(--danger);
  color: white;
}

.filter-bar,
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid #cbd4cd;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid #d9c79f;
  border-radius: 8px;
  background: #fff8e8;
  color: #68440c;
}

.view {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-recent {
  margin-top: 24px;
}

.kpi-card,
.panel,
.result-panel,
.form-section,
.detail-header {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  min-height: 130px;
}

.kpi-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-header span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-header strong {
  font-size: 30px;
  line-height: 1.1;
  color: var(--text);
}

.kpi-breakdown {
  color: var(--muted);
  font-size: 12px;
}

.kpi-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.kpi-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.kpi-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.kpi-sparkline {
  margin-top: auto;
  display: flex;
  align-items: flex-end;
}

.sparkline {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* "위험" KPI: gentle warm tint when there's anything to act on */
.kpi-at-risk.is-active {
  background: #fff7ee;
  border-color: #f0d4b2;
}

.kpi-at-risk.is-active .kpi-header strong {
  color: #b3540f;
}

/* Tier-stack horizontal bar under "활성 라이선스" */
.kpi-stacked {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stack-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.04);
}

.stack-segment {
  height: 100%;
}

.stack-empty {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

/* Pipeline bars */
.pipeline-buckets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.pipeline-row {
  display: grid;
  grid-template-columns: 80px 1fr 32px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.pipeline-label {
  color: var(--muted);
}

.pipeline-bar-wrap {
  height: 10px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 5px;
  overflow: hidden;
}

.pipeline-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  min-width: 2px;
}

.pipeline-danger .pipeline-bar {
  background: var(--danger);
}

.pipeline-warn .pipeline-bar {
  background: #e0a64a;
}

.pipeline-count {
  text-align: right;
  color: var(--text);
  font-weight: 600;
}

.pipeline-empty {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

/* This-month activity card */
.activity-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.activity-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-stat span {
  font-size: 11px;
  color: var(--muted);
}

.activity-stat strong {
  font-size: 22px;
  line-height: 1.1;
}

/* Top organizations list */
.top-orgs {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  counter-reset: top-org;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.top-orgs li {
  counter-increment: top-org;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}

.top-orgs li:hover {
  background: rgba(0, 0, 0, 0.04);
}

.top-orgs li::before {
  content: counter(top-org);
  flex: 0 0 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.top-org-line {
  display: flex;
  flex: 1;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.top-org-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-org-stats {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.top-orgs .empty {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  cursor: default;
}

.top-orgs .empty::before {
  display: none;
}

.work-grid,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.panel,
.result-panel,
.form-section,
.detail-header {
  padding: 16px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.list,
.activation-list {
  display: grid;
  gap: 8px;
}

.list-item,
.activation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid #eef1ee;
}

.list-item:first-child,
.activation-item:first-child {
  border-top: 0;
}

.list-title {
  font-weight: 700;
}

.list-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  padding: 14px 0;
}

.filter-bar {
  grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(130px, 1fr)) auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.audit-filter {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(150px, 0.8fr) auto;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.table-actions {
  display: flex;
  justify-content: flex-end;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.pager span {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #eef1ee;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f3f7f4;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf4ef;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.warn {
  background: #fff2d9;
  color: var(--warn);
}

.status-pill.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-pill.neutral {
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
}

.issue-form {
  display: grid;
  gap: 12px;
  max-width: 840px;
}

.form-section {
  display: grid;
  gap: 12px;
  box-shadow: none;
}

.form-section .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
}

.segmented button.is-selected {
  border-color: #8caf99;
  background: #e8f2ea;
  color: var(--accent-strong);
  font-weight: 760;
}

.result-panel {
  display: grid;
  gap: 10px;
  max-width: 840px;
}

.license-key-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid #b8c7bc;
  border-radius: 8px;
  background: #f1f7f2;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.detail-title {
  font-size: 24px;
  font-weight: 780;
}

.kv {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.kv div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.activation-item {
  grid-template-columns: 96px minmax(0, 1fr) auto;
}

/* ─── Issue page: mode tabs ─────────────────────────────────────────── */

.issue-mode-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.issue-mode-tabs .tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.issue-mode-tabs .tab + .tab {
  border-left: 1px solid var(--line);
}

.issue-mode-tabs .tab.is-selected {
  background: var(--accent);
  color: #fff;
}

/* ─── Customer info: inline edit ────────────────────────────────────── */

.customer-edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.customer-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.customer-edit-form input,
.customer-edit-form textarea {
  font-size: 13px;
  color: var(--text);
  font-weight: 400;
}

.customer-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ─── AutoSuggestBox ────────────────────────────────────────────────── */

.autosuggest {
  position: relative;
}

.autosuggest-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 20;
  max-height: 240px;
  overflow-y: auto;
}

.autosuggest-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}

.autosuggest-list li:hover {
  background: rgba(0, 0, 0, 0.04);
}

.autosuggest-list li small {
  color: var(--muted);
  font-size: 11px;
}

/* ─── Bulk CSV issue ────────────────────────────────────────────────── */

.bulk-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.bulk-file-button {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.bulk-file-button:hover {
  background: rgba(0, 0, 0, 0.04);
}

.bulk-file-name {
  font-size: 12px;
  color: var(--muted);
}

.bulk-format-spec {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
  background: rgba(0, 0, 0, 0.02);
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.bulk-format-spec code {
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.bulk-format-spec ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.bulk-summary {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
}

.bulk-preview-table,
.bulk-result-table {
  font-size: 12px;
}

.bulk-preview-table tr.is-invalid,
.bulk-result-table tr.is-invalid {
  background: rgba(237, 60, 60, 0.04);
}

.bulk-preview-table tr.is-valid .status-pill,
.bulk-result-table tr.is-valid .status-pill {
  background: rgba(0, 128, 0, 0.08);
  color: #1a6e1a;
}

.email-template {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.email-template-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.email-template-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.email-template-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-template-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.email-template-tabs .tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.email-template-tabs .tab + .tab {
  border-left: 1px solid var(--line);
}

.email-template-tabs .tab.is-selected {
  background: var(--accent);
  color: #fff;
}

.email-template-assignee {
  max-width: 320px;
}

.email-template-text {
  width: 100%;
  min-height: 360px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
  box-sizing: border-box;
}

.danger-zone {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  background: #fffafa;
  border-color: #edc6c2;
}

.danger-zone h2 {
  margin: 0;
}

.panel-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.danger-zone .panel-hint {
  margin: 0;
}

/* Required-field marker + per-field helper text on the issue form */
.req {
  color: var(--danger);
  font-weight: 700;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Live "기본 만료일 → 연장 후" preview under the issue form's period fields */
.expiry-preview {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 650;
}

.expiry-preview:empty {
  display: none;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(20, 28, 23, 0.35);
}

.confirm-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.confirm-dialog p {
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .main {
    padding: 22px 16px 36px;
  }

  .topbar,
  .detail-header {
    display: grid;
  }

  .filter-bar,
  .kpi-grid,
  .work-grid,
  .detail-grid,
  .form-section .form-grid,
  .segmented,
  .activity-stats {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }
}
