:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --line: #d9e1e7;
  --text: #17212b;
  --muted: #697785;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --blue: #2563eb;
  --danger: #b42318;
  --warning: #b35c00;
  --success: #15803d;
  --shadow: 0 12px 32px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.08), rgba(37, 99, 235, 0.07)),
    var(--bg);
}

.login-panel {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
  display: grid;
  gap: 28px;
}

.login-panel h1,
.topbar h1,
.brand-block h2 {
  margin: 0;
}

.login-panel h1 {
  font-size: 34px;
}

.login-copy {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #293746;
  font-size: 13px;
  font-weight: 700;
}

.checkbox-label {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  border-color: var(--primary);
}

.primary-button,
.ghost-button,
.table-action,
.nav-button,
.shortcut-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  font-weight: 800;
  white-space: nowrap;
}

.compact-button {
  min-height: 32px;
  padding: 5px 10px;
}

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

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

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.ghost-button:hover {
  border-color: #b5c3ce;
}

.danger-button {
  color: var(--danger);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #12212a;
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  padding: 8px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-block .eyebrow {
  color: #83d8ce;
}

.brand-block h2 {
  font-size: 22px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #dbe7ee;
  background: transparent;
  border-color: transparent;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.11);
}

.nav-button span {
  color: #83d8ce;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px;
  display: grid;
  align-content: start;
  gap: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar h1 {
  font-size: 28px;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.company-filter {
  min-width: 190px;
  display: grid;
  grid-template-columns: auto minmax(130px, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.company-filter select {
  min-height: 36px;
  padding: 7px 9px;
}

.role-badge,
.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: #e8f5f3;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.page {
  display: none;
  gap: 18px;
}

.page.active {
  display: grid;
}

.alert-band {
  display: grid;
  gap: 10px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #f0cf9e;
  border-left: 5px solid var(--warning);
  background: #fff8ed;
  border-radius: 6px;
  padding: 12px 14px;
}

.alert-item strong {
  display: block;
}

.alert-item span {
  color: #7d4a03;
  font-size: 13px;
}

.shortcut-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.shortcut-button {
  min-height: 82px;
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.04);
  text-align: left;
  display: grid;
  align-content: center;
  gap: 6px;
}

.shortcut-button strong {
  font-size: 16px;
}

.shortcut-button span {
  color: var(--muted);
  font-size: 12px;
}

.shortcut-button:hover {
  border-color: var(--primary);
}

.metric-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.04);
}

.metric-card {
  padding: 18px;
  display: grid;
  gap: 9px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 23px;
}

.two-column,
.split-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.split-layout {
  align-items: start;
}

.contract-workspace,
.order-workspace {
  display: grid;
  gap: 18px;
}

.vendor-workspace {
  display: grid;
  gap: 18px;
}

.panel {
  min-width: 0;
}

.panel-heading {
  min-height: 62px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
}

.contract-info-panel {
  border-color: rgba(15, 118, 110, 0.34);
}

.contract-info-panel .panel-heading {
  background: #eaf7f5;
  border-left: 5px solid var(--primary);
}

.with-filter {
  align-items: center;
}

.heading-actions,
.button-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.heading-actions {
  flex-wrap: wrap;
}

.with-filter input,
.with-filter select,
.inline-controls select {
  max-width: 210px;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-button {
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.file-button input {
  display: none;
}

.form-panel {
  position: sticky;
  top: 20px;
}

.form-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .wide,
.form-actions {
  grid-column: 1 / -1;
}

.date-row,
.type-section,
.inline-pair,
.amount-payment-row,
.contract-section {
  display: grid;
  gap: 12px;
}

.date-row {
  grid-template-columns: repeat(auto-fit, minmax(136px, 160px));
  align-items: end;
  justify-content: start;
}

.amount-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 10px;
}

.amount-payment-row {
  grid-template-columns: minmax(240px, 360px) minmax(190px, 260px);
  align-items: start;
}

.amount-korean {
  min-width: 140px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
}

.type-section {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.contract-section {
  grid-template-columns: 1fr;
  padding: 14px;
  border: 1px solid #c9ddd9;
  border-radius: 8px;
  background: #fbfefd;
  border-top: 4px solid var(--primary);
}

#contractInfoSection {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-due-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  gap: 12px;
  align-items: end;
}

.split-date {
  display: grid;
  grid-template-columns: 4.1em 0.35em 2.65em 0.35em 2.65em;
  align-items: center;
  gap: 4px;
}

.split-date input {
  min-height: 40px;
  padding: 8px 5px;
  text-align: center;
}

.split-date span {
  color: var(--muted);
  font-weight: 900;
}

.cost-input-grid,
.profit-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.profit-summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.profit-summary-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.profit-summary-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.profit-summary-grid strong {
  font-size: 16px;
  text-align: right;
}

.compact-table table {
  min-width: 520px;
}

.compact-table th,
.compact-table td {
  padding: 9px 10px;
  font-size: 13px;
}

.permission-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.section-title {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
}

.progress-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.progress-item {
  display: grid;
  grid-template-columns: minmax(72px, 0.7fr) minmax(130px, 1fr) minmax(130px, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.inline-pair {
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

#vendorsPage table {
  min-width: 1320px;
}

#vendorsPage th,
#vendorsPage td {
  white-space: nowrap;
}

#vendorsPage .wrap-cell {
  min-width: 180px;
  max-width: 300px;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

#vendorsPage .description-cell {
  min-width: 220px;
  max-width: 360px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: #51606e;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 900;
}

tbody tr:hover {
  background: #fbfcfd;
}

tbody tr.selectable-row {
  cursor: pointer;
}

tbody tr.is-selected {
  background: #eef7f6;
  box-shadow: inset 4px 0 0 var(--primary);
}

.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
}

.table-actions {
  display: flex;
  gap: 6px;
}

.table-action {
  min-height: 32px;
  padding: 6px 9px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.table-action.edit {
  color: var(--blue);
}

.table-action.delete {
  color: var(--danger);
}

.empty-row {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.empty-box {
  color: var(--muted);
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.status-danger {
  background: #fff0ee;
  color: var(--danger);
}

.status-warning {
  background: #fff4df;
  color: #875000;
}

.status-success {
  background: #eaf7ee;
  color: var(--success);
}

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

  .two-column,
  .split-layout {
    grid-template-columns: 1fr;
  }

  .type-section,
  .cost-input-grid,
  .profit-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-panel {
    position: static;
  }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 20px;
  }

  .topbar,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-actions,
  .inline-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .company-filter {
    width: 100%;
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .shortcut-grid,
  .metric-grid,
  .form-grid,
  .date-row,
  .type-section,
  .permission-group,
  .inline-pair,
  .amount-input-row,
  .amount-payment-row,
  .status-due-row,
  .cost-input-grid,
  .profit-summary-grid,
  .progress-item {
    grid-template-columns: 1fr;
  }

  #contractInfoSection {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 24px;
  }

  .login-panel h1 {
    font-size: 28px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .with-filter input,
  .with-filter select,
  .inline-controls select {
    max-width: none;
  }
}
