:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #dfe4ec;
  --border-strong: #c8d1de;
  --text: #172033;
  --text-muted: #5a667d;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --success: #0f766e;
  --success-soft: #ecfdf5;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

/* Header */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

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

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.full-width {
  width: 100%;
}

/* Mode Switcher */
.mode-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.mode-tab {
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.96rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-tab .mode-hint {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.85;
}

.mode-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
}

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.controls-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sticky-results {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
}

.pill {
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}

/* Form Elements */
.form-grid {
  display: grid;
  gap: 12px;
}

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

.salary-grid {
  grid-template-columns: 125px 1fr;
}

.stack-gap {
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.label-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
}

input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

input[type="number"]:focus,
select:focus {
  outline: 2px solid rgba(29, 78, 216, 0.25);
  border-color: var(--primary);
}

.compact-field {
  max-width: 220px;
}

.optional-block,
.rule-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.rule-block:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-row strong {
  display: block;
  font-size: 0.93rem;
}

.toggle-row small {
  display: block;
  color: var(--text-muted);
  font-size: 0.81rem;
  margin-top: 1px;
}

.sub-panel {
  margin-top: 10px;
  margin-left: 28px;
  padding: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.sub-note {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.inline-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* Hero Result Card */
.hero-card {
  background: linear-gradient(145deg, #0f172a 0%, #1e3a8a 100%);
  color: #ffffff;
  border: none;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hero-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.82);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.22);
  color: #a7f3d0;
}

.status-badge.has-cut {
  background: rgba(245, 158, 11, 0.24);
  color: #fde68a;
}

.status-badge.zero-pay {
  background: rgba(239, 68, 68, 0.28);
  color: #fecaca;
}

.hero-metric {
  margin-top: 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.hero-number {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.hero-unit {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.82);
  font-weight: 500;
}

.hero-salary {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.11);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.salary-label {
  display: block;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.75);
}

.salary-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.salary-right {
  text-align: right;
}

.salary-cut {
  font-size: 1.05rem;
  color: #fde68a;
}

.plain-summary {
  margin: 14px 0 0;
  font-size: 0.89rem;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.5;
}

/* Breakdown Card */
.breakdown-card h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.breakdown-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}

.breakdown-row dt {
  color: var(--text-muted);
}

.breakdown-row dd {
  margin: 0;
  font-weight: 700;
}

.breakdown-row.highlight-danger dd {
  color: var(--danger);
}

.balance-box {
  margin-top: 14px;
  padding: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.balance-box h4 {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.balance-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
}

.balance-item span {
  display: block;
  font-size: 0.77rem;
  color: var(--text-muted);
}

.balance-item strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  color: var(--success);
}

.result-actions {
  margin-top: 14px;
  text-align: center;
}

.copy-feedback {
  display: block;
  min-height: 18px;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--success);
  font-weight: 600;
}

/* Annual Table */
.annual-section {
  margin-top: 22px;
}

.annual-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.annual-header h2 {
  margin: 0;
  font-size: 1.12rem;
}

.annual-quick-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-fill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.quick-fill input {
  width: 74px;
  padding: 7px 9px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 780px;
}

.ledger-table th,
.ledger-table td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.ledger-table th:first-child,
.ledger-table td:first-child {
  text-align: left;
  font-weight: 600;
}

.ledger-table thead th {
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ledger-table tbody tr:hover {
  background: #fafcff;
}

.ledger-table tfoot td {
  background: var(--primary-soft);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}

.table-input {
  width: 76px !important;
  padding: 5px 7px !important;
  text-align: right;
  font-size: 0.86rem !important;
}

.cell-cut {
  color: var(--danger);
  font-weight: 700;
}

.cell-payable {
  color: var(--primary);
  font-weight: 700;
}

/* Responsive */
@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sticky-results {
    position: static;
  }
}

@media (max-width: 560px) {
  .two-col,
  .salary-grid,
  .mode-switcher,
  .balance-grid {
    grid-template-columns: 1fr;
  }

  .sub-panel {
    margin-left: 0;
  }

  .hero-number {
    font-size: 2.4rem;
  }
}

/* Print Styles */
@media print {
  body {
    background: #fff;
  }

  .top-actions,
  .mode-switcher,
  .result-actions,
  .annual-quick-tools {
    display: none !important;
  }

  .card {
    box-shadow: none;
    break-inside: avoid;
  }

  .hero-card {
    background: #1e3a8a !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
