:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #6e7a72;
  --line: #dfe5df;
  --primary: #146c53;
  --primary-dark: #0f4d3d;
  --sidebar-bg: #101815;
  --sidebar-soft: #1d2924;
  --sidebar-hover: #23322c;
  --accent: #d58936;
  --danger: #b33131;
  --ok: #1f7a45;
  --warn: #a96212;
  --shadow: 0 18px 50px rgba(23, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  min-width: 0;
}

.sidebar {
  min-height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar-bg);
  color: #f4faf6;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1208;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
  overflow-wrap: anywhere;
}

.brand span {
  color: #b7c7be;
  font-size: 13px;
}

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

.nav-item {
  border: 0;
  color: #dce7e0;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item.active,
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-card {
  margin-top: auto;
  background: var(--sidebar-soft);
  border: 1px solid #31443b;
  border-radius: 8px;
  padding: 16px;
}

.sidebar-card span {
  display: block;
  color: #b7c7be;
  font-size: 13px;
  margin-bottom: 8px;
}

.sidebar-card strong {
  font-size: 24px;
}

.app {
  min-width: 0;
  padding: clamp(22px, 3.4vw, 42px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 30px;
  min-width: 0;
}

.topbar > div:first-child {
  min-width: 180px;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 42px);
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 280px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  min-width: min(260px, 100%);
}

.search input,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  min-height: 42px;
}

input[type="color"] {
  padding: 4px;
}

textarea {
  resize: vertical;
  min-height: 92px;
}

.btn,
.quick,
.tab {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
}

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

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

.btn.ghost,
.tab {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.btn.disabled {
  pointer-events: none;
  opacity: 0.55;
}

.cloud-status {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.cloud-status.cloud {
  color: var(--ok);
  border-color: #b8dec7;
  background: #eef9f1;
}

.cloud-status.syncing {
  color: var(--warn);
  border-color: #f1d4aa;
  background: #fff8ed;
}

.cloud-status.offline {
  color: var(--danger);
  border-color: #f1c7c7;
  background: #fff3f3;
}

.btn.danger {
  background: #fff3f3;
  color: var(--danger);
  border-color: #f1c7c7;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}

.metrics.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.finance-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

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

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 22px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: clamp(22px, 2.8vw, 34px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.85fr);
  gap: 20px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.panel-head > * {
  min-width: 0;
}

.panel-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.order-list,
.payment-list,
.client-grid,
.mini-section {
  padding: 20px;
}

.order-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 14px;
  background: #fbfcfb;
}

.order-card:last-child {
  margin-bottom: 0;
}

.order-title {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 6px;
}

.order-title strong {
  font-size: 16px;
}

.order-meta,
.muted {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.badge {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #edf4f0;
  color: var(--primary);
}

.badge.warn {
  color: var(--warn);
  background: #fff4e7;
}

.badge.ok {
  color: var(--ok);
  background: #eaf7ef;
}

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

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

.link-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  width: max-content;
  font-weight: 800;
  text-align: left;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 16px;
}

.quick {
  width: 100%;
  background: #f7faf7;
  border-color: var(--line);
  justify-content: flex-start;
}

.mini-list {
  display: grid;
  gap: 10px;
}

.mini-item,
.payment-item,
.client-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 16px;
}

.client-card strong,
.payment-item strong {
  display: block;
  margin-bottom: 5px;
}

.client-card.wide {
  display: grid;
  gap: 12px;
}

.client-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  min-width: 0;
}

.client-head > div:first-child {
  min-width: 0;
}

.client-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.client-stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.client-note {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 13px;
  padding-left: 10px;
}

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

.history-item {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: grid;
  gap: 3px;
}

.history-item span,
.history-item small {
  color: var(--muted);
  font-size: 12px;
}

.payment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, auto);
  gap: 24px;
  align-items: center;
  margin-bottom: 10px;
}

.payment-values {
  text-align: right;
  display: grid;
  gap: 6px;
  align-content: start;
}

.finance-equation {
  margin-top: 12px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.finance-equation.secondary {
  margin-top: 6px;
  color: var(--muted);
}

.finance-tools {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 20px;
}

.finance-tools label {
  width: min(240px, 100%);
}

.detail-body {
  display: grid;
  gap: 16px;
}

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

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}

.detail-item strong {
  overflow-wrap: anywhere;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.detail-section p {
  color: var(--muted);
  margin-bottom: 0;
}

.audit-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf8;
  margin-top: 8px;
}

.modal {
  width: min(1080px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.28);
  padding: 0;
}

.modal.small {
  width: min(620px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(13, 19, 16, 0.58);
}

.modal-body {
  padding: 24px;
  min-width: 0;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

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

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.check-row {
  display: flex;
  align-items: start;
  gap: 10px;
  line-height: 1.4;
}

.check-row input {
  min-height: 0;
  margin-top: 3px;
}

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

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.modal-actions > div {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.message-box {
  width: 100%;
  min-height: 180px;
}

.settings-form {
  padding: 20px;
}

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

@media (max-width: 960px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 14px;
    flex-direction: row;
    align-items: center;
    overflow: auto;
    gap: 14px;
  }

  .nav {
    display: flex;
    min-width: max-content;
  }

  .sidebar-card {
    display: none;
  }

  .topbar,
  .dashboard-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-actions {
    justify-content: flex-start;
    min-width: 0;
  }

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

  .finance-summary,
  .finance-breakdown {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app {
    padding: 18px 12px;
  }

  h1 {
    font-size: 30px;
  }

  .brand span {
    display: none;
  }

  .topbar-actions,
  .search,
  .search input {
    width: 100%;
  }

  .topbar-actions .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 128px;
  }

  .metrics,
  .metrics.compact,
  .finance-summary,
  .finance-breakdown,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .order-card,
  .payment-item {
    grid-template-columns: 1fr;
  }

  .card-actions,
  .table-actions,
  .modal-actions > div {
    justify-content: stretch;
  }

  .card-actions .btn,
  .table-actions .btn,
  .payment-values .btn,
  .modal-actions .btn {
    flex: 1 1 auto;
  }

  .order-card .card-actions {
    display: grid;
    grid-template-columns: repeat(3, 38px);
    justify-content: start;
  }

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

  .client-head {
    display: grid;
  }

  .client-head .card-actions {
    justify-content: start;
  }

  .client-head,
  .finance-tools {
    display: grid;
  }

  .payment-values {
    text-align: left;
  }

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

  .modal-actions,
  .modal-actions > div {
    flex-direction: column;
    align-items: stretch;
  }

  .modal {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .modal-body {
    padding: 14px;
  }

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