:root {
  --bg: #f4efe7;
  --panel: #fffdf9;
  --panel-soft: #f8f3eb;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d9cfbf;
  --brand: #1f4d3b;
  --brand-soft: #dcefe4;
  --brand-dark: #163b2d;
  --danger: #a63d40;
  --danger-soft: #fbe8e8;
  --success: #246b45;
  --success-soft: #e7f5ec;
  --shadow: 0 18px 45px rgba(45, 35, 20, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(31, 77, 59, 0.14), transparent 32%),
    linear-gradient(180deg, #fbf7f1 0%, var(--bg) 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  background: #f2ebe0;
  padding: 2px 6px;
  border-radius: 6px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #163b2d 0%, #214a39 100%);
  color: #f8fafc;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-subtitle,
.sidebar-role,
.muted {
  color: rgba(248, 250, 252, 0.72);
}

.sidebar-user {
  font-weight: 600;
}

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

.nav-stack::-webkit-scrollbar {
  display: none;
}

.nav-link {
  padding: 12px 14px;
  border-radius: 14px;
  color: rgba(248, 250, 252, 0.86);
}

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

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  display: grid;
  gap: 6px;
}

.ghost-link {
  color: #dbeafe;
}

.main-panel {
  padding: 28px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-header h1,
.login-card h1 {
  margin: 6px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--muted);
}

.flash {
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}

.flash-success {
  background: var(--success-soft);
  border-color: #c2e5cf;
  color: var(--success);
}

.flash-error {
  background: var(--danger-soft);
  border-color: #efc6c6;
  color: var(--danger);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.metric-card,
.content-card,
.detail-card,
.login-card {
  background: rgba(255, 253, 249, 0.92);
  border: 1px solid rgba(217, 207, 191, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 20px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.metric-value {
  margin-top: 12px;
  font-size: 2rem;
  font-weight: 700;
  color: var(--brand-dark);
}

.content-card {
  padding: 22px;
  margin-bottom: 20px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.section-head.compact {
  margin-top: 8px;
}

.section-head h2,
.section-head h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

.table-wrap {
  overflow-x: auto;
}

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

.stack-section table {
  min-width: 620px;
}

th,
td {
  text-align: left;
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.table-link {
  color: var(--brand);
  font-weight: 600;
}

.strong-link {
  font-weight: 800;
}

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

.split-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(0, 1.08fr);
  gap: 20px;
}

.stack-section {
  display: grid;
  gap: 20px;
}

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

.form-stack {
  display: grid;
  gap: 16px;
}

.field-span-2 {
  grid-column: span 2;
}

.field-limit {
  max-width: 460px;
}

.field-limit-wide {
  max-width: 680px;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(31, 77, 59, 0.18);
  border-color: var(--brand);
}

textarea {
  resize: vertical;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-line input {
  width: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  cursor: pointer;
}

.button-primary {
  background: linear-gradient(135deg, var(--brand) 0%, #2d7057 100%);
  color: #fff;
}

.button-secondary {
  background: #efe7da;
  color: var(--brand-dark);
}

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

.button-small {
  padding: 8px 12px;
  font-size: 0.84rem;
}

.action-row,
.filter-row,
.mini-summary {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.table-actions {
  align-items: stretch;
}

.table-actions > .button,
.table-actions > .inline-form {
  flex: 1 1 auto;
}

.table-actions > .inline-form .button {
  width: 100%;
}

.invoice-detail-actions {
  justify-content: flex-end;
}

.mini-summary {
  margin-bottom: 18px;
  color: var(--muted);
}

.filter-row {
  margin-bottom: 18px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-active {
  background: var(--success-soft);
  color: var(--success);
}

.status-inactive {
  background: #f3f4f6;
  color: #475467;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.detail-card {
  padding: 16px;
}

.detail-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-value {
  margin-top: 8px;
  font-weight: 700;
  font-size: 1rem;
}

.address-box,
.total-panel {
  background: var(--panel-soft);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
}

.total-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.08rem;
}

.small {
  font-size: 0.84rem;
  color: var(--muted);
}

.muted-body {
  color: #5f6b7a;
  margin: 0 0 14px;
}

.inline-notice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 16px;
}

#invoice-items-table {
  min-width: 960px;
}

#invoice-items-table th:nth-child(1),
#invoice-items-table td:nth-child(1) {
  width: 42%;
}

#invoice-items-table th:nth-child(2),
#invoice-items-table td:nth-child(2) {
  width: 18%;
}

#invoice-items-table th:nth-child(3),
#invoice-items-table td:nth-child(3) {
  width: 22%;
}

#invoice-items-table th:nth-child(4),
#invoice-items-table td:nth-child(4) {
  width: 18%;
}

#invoice-items-table select,
#invoice-items-table input {
  min-height: 48px;
}

.invoice-product-cell select {
  min-width: 320px;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(520px, 100%);
  padding: 32px;
}

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

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

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

  .sidebar {
    position: static;
    height: auto;
    padding: 18px 16px;
    gap: 14px;
  }

  .main-panel {
    padding: 18px;
  }

  .nav-stack {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-link {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .card-grid,
  .detail-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .inline-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .field-span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 640px) {
  body {
    overflow-x: hidden;
  }

  .brand-mark {
    font-size: 1.2rem;
  }

  .main-panel,
  .login-wrap {
    padding: 14px;
  }

  .content-card,
  .login-card {
    padding: 16px;
    border-radius: 18px;
  }

  .metric-card,
  .detail-card {
    border-radius: 18px;
  }

  .page-header,
  .section-head,
  .section-head.compact,
  .action-row,
  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .field-limit,
  .field-limit-wide {
    max-width: none;
  }

  .action-row .button,
  .filter-row .button,
  .section-head .button {
    width: 100%;
  }

  .mini-summary {
    display: grid;
    gap: 8px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  .stack-section table,
  #invoice-items-table {
    min-width: 0;
  }

  table thead {
    display: none;
  }

  table,
  table tbody,
  table tr,
  table td {
    display: block;
    width: 100%;
  }

  table tr {
    background: rgba(255, 253, 249, 0.96);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 14px;
    box-shadow: 0 10px 24px rgba(45, 35, 20, 0.06);
  }

  table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 0;
    text-align: left;
    align-items: flex-start;
  }

  table td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    max-width: 40%;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 700;
    line-height: 1.35;
  }

  table td > * {
    margin-left: auto;
  }

  table td .action-row {
    width: 100%;
    align-items: stretch;
  }

  table td[data-label="Aksi"] {
    display: block;
  }

  table td[data-label="Aksi"]::before {
    display: block;
    max-width: none;
    margin-bottom: 10px;
  }

  table td[data-label="Aksi"] > * {
    margin-left: 0;
  }

  .table-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .table-actions > .button,
  .table-actions > .inline-form {
    width: 100%;
    margin: 0;
  }

  .table-actions > .inline-form {
    display: block;
  }

  .invoice-detail-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
  }

  .invoice-detail-actions .button {
    width: 100%;
    margin: 0;
  }

  table td .inline-form {
    margin-left: auto;
  }

  table td.empty-state {
    display: block;
    text-align: center;
    padding: 16px 0;
  }

  table td.empty-state::before {
    content: none;
  }

  .invoice-product-cell select {
    min-width: 0;
  }

  #invoice-items-table td::before {
    flex-basis: 34%;
    max-width: 36%;
  }

  #invoice-items-table select,
  #invoice-items-table input,
  #invoice-items-table .button {
    width: 100%;
  }
}
