:root {
  color-scheme: dark;
  --bg: #090b0b;
  --surface: #151412;
  --surface-2: #1d1b18;
  --surface-3: #24211d;
  --ink: #fffaf2;
  --muted: #b9afa2;
  --faint: #837a70;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.24);
  --teal: #58bfae;
  --blue: #75a9df;
  --amber: #f0bf72;
  --red: #ef6f61;
  --violet: #b489e8;
  --green: #62c58b;
  --shadow: 0 22px 42px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --font: "Segoe UI", Arial, Helvetica, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #f1f4f5;
  --surface-3: #e8eef0;
  --ink: #17201e;
  --muted: #5d6a66;
  --faint: #7c8b86;
  --line: rgba(23, 32, 30, 0.13);
  --line-strong: rgba(23, 32, 30, 0.24);
  --shadow: 0 18px 34px rgba(31, 46, 43, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 108px;
  background:
    radial-gradient(circle at 22% 0%, rgba(88, 191, 174, 0.13), transparent 32rem),
    linear-gradient(180deg, #11100e 0, var(--bg) 340px),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:root[data-theme="light"] body {
  background:
    radial-gradient(circle at 22% 0%, rgba(88, 191, 174, 0.15), transparent 30rem),
    linear-gradient(180deg, #fbfcfc 0, var(--bg) 340px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 760;
}

button:hover {
  border-color: var(--line-strong);
}

button:focus-visible,
input:focus,
select:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(88, 191, 174, 0.18);
  outline-offset: 1px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.32rem, 3vw, 1.86rem);
  line-height: 1.02;
  letter-spacing: 0;
  font-weight: 850;
}

h2 {
  font-size: 1.22rem;
  line-height: 1.15;
  letter-spacing: 0;
  font-weight: 850;
}

h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: 0;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.24);
  color: var(--ink);
  padding: 0 12px;
}

:root[data-theme="light"] input,
:root[data-theme="light"] select {
  background: #fff;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 780;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sprite,
.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 7px 7px 28px;
}

.hero {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 0 0 18px 18px;
  background: rgba(21, 20, 18, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

:root[data-theme="light"] .hero {
  background: rgba(255, 255, 255, 0.9);
}

.brand-row,
.brand-title,
.hero-actions,
.panel-head > div,
.tool-buttons,
.form-actions,
.record-actions,
.status-pill,
.primary-button,
.soft-button,
.text-button,
.search-box,
.section-icon,
.bottom-nav,
.nav-item {
  display: flex;
  align-items: center;
}

.brand-row {
  justify-content: space-between;
  gap: 18px;
}

.brand-lockup {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.mini-kicker {
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 820;
}

.brand-title {
  gap: 12px;
  min-width: 0;
}

.brand-title p,
.panel-head p,
.note {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 680;
}

.brand-logo {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  object-fit: contain;
  padding: 4px;
}

.hero-actions {
  gap: 8px;
}

.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 999px;
}

.icon-button span {
  position: absolute;
  right: 7px;
  top: 4px;
  color: var(--ink);
  font-size: 0.78rem;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  margin: 0;
}

.metric {
  min-width: 0;
  min-height: 60px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(29, 27, 24, 0.94);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

:root[data-theme="light"] .metric {
  background: #fff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 840;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.metric.active {
  border-left-color: var(--green);
}

.metric.soon {
  border-left-color: var(--blue);
}

.metric.late {
  border-left-color: var(--red);
}

.metric.money {
  border-left-color: var(--violet);
}

.view {
  display: none;
  margin-top: 14px;
}

.view.active {
  display: grid;
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(21, 20, 18, 0.9);
  box-shadow: var(--shadow);
}

:root[data-theme="light"] .panel {
  background: rgba(255, 255, 255, 0.94);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-head > div {
  gap: 12px;
  min-width: 0;
}

.section-icon {
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--amber);
}

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

.form-footer {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.form-footer p {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 760;
}

.form-actions {
  gap: 8px;
}

.primary-button,
.soft-button,
.text-button {
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
}

.primary-button {
  border-color: transparent;
  background: #2f6f96;
  color: #fff;
}

.ghost-button {
  padding: 0 13px;
  background: transparent;
}

.soft-button {
  background: var(--surface-2);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
}

.list-tools {
  display: grid;
  grid-template-columns: minmax(160px, 230px) 92px;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  gap: 8px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
}

.search-box input {
  min-height: 42px;
  border: 0;
  padding: 0;
  background: transparent;
}

.records-list,
.customer-grid,
.timeline,
.analysis-grid,
.monthly-report {
  display: grid;
  gap: 10px;
}

.records-list.roomy {
  gap: 12px;
}

.record-card {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(120px, 0.62fr) 100px 112px 116px 112px auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 12px 10px 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
}

:root[data-theme="light"] .record-card {
  background: #fff;
}

.record-main,
.record-person {
  min-width: 0;
}

.record-main strong,
.record-person strong,
.customer-card strong,
.timeline-card strong {
  display: block;
  overflow-wrap: anywhere;
}

.record-main p,
.record-person p,
.empty-state,
.timeline-card p,
.customer-card p,
.analysis-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
  overflow-wrap: anywhere;
}

.record-amount,
.record-date,
.record-balance {
  font-weight: 860;
}

.record-amount small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.record-balance {
  color: var(--amber);
  font-size: 0.84rem;
}

.status-pill {
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 860;
  white-space: nowrap;
}

.status-normal {
  background: rgba(88, 191, 174, 0.13);
  color: var(--teal);
}

.status-soon {
  background: rgba(117, 169, 223, 0.14);
  color: var(--blue);
}

.status-late {
  background: rgba(239, 111, 97, 0.13);
  color: var(--red);
}

.status-done {
  background: rgba(98, 197, 139, 0.14);
  color: var(--green);
}

.status-archive {
  background: rgba(131, 122, 112, 0.18);
  color: var(--muted);
}

.payment-unpaid {
  background: rgba(239, 111, 97, 0.13);
  color: var(--red);
}

.payment-partial {
  background: rgba(240, 191, 114, 0.15);
  color: var(--amber);
}

.payment-paid {
  background: rgba(98, 197, 139, 0.14);
  color: var(--green);
}

.record-card.done {
  opacity: 0.68;
}

.record-card.done .record-main strong {
  text-decoration: line-through;
}

.record-actions {
  justify-content: flex-end;
  gap: 6px;
}

.action-button {
  display: grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--ink);
}

.action-button.call {
  color: var(--blue);
}

.action-button.whatsapp {
  color: var(--green);
}

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

.empty-state {
  min-height: 66px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.customer-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.customer-card,
.timeline-card,
.analysis-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.14);
}

:root[data-theme="light"] .customer-card,
:root[data-theme="light"] .timeline-card,
:root[data-theme="light"] .analysis-card {
  background: #fff;
}

.customer-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  cursor: pointer;
}

.customer-card em,
.analysis-card strong {
  color: var(--teal);
  font-style: normal;
  font-size: 1.12rem;
  font-weight: 900;
}

.timeline-card {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.timeline-date {
  color: var(--amber);
  font-weight: 880;
}

.analysis-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.analysis-card {
  display: grid;
  gap: 4px;
}

.report-tools {
  display: grid;
  grid-template-columns: minmax(180px, 240px) max-content;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.monthly-report,
.customer-detail {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.14);
}

:root[data-theme="light"] .monthly-report,
:root[data-theme="light"] .customer-detail {
  background: #fff;
}

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

.detail-head p,
.detail-list p,
.monthly-report p {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 680;
}

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

.detail-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 112px 100px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(160px, 240px) max-content;
  gap: 12px;
  align-items: end;
}

.settings-sections {
  display: grid;
  gap: 12px;
}

.settings-card {
  display: grid;
  grid-template-columns: minmax(190px, 250px) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  min-height: 98px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.14);
}

:root[data-theme="light"] .settings-card {
  background: #fff;
}

.settings-card p,
.device-code {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 680;
}

.settings-card-title {
  display: grid;
  gap: 4px;
  align-content: center;
  min-width: 0;
}

.settings-card-body {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.license-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(88, 191, 174, 0.09);
}

.license-status span {
  color: var(--muted);
  font-weight: 780;
}

.license-status strong {
  color: var(--teal);
}

.license-line,
.backup-actions,
.cloud-line {
  display: grid;
  gap: 10px;
  align-items: end;
}

.license-line {
  grid-template-columns: minmax(220px, 1fr) max-content max-content;
}

.backup-actions {
  grid-template-columns: repeat(3, minmax(140px, max-content));
  justify-content: start;
}

.cloud-line {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 0.7fr) repeat(3, max-content);
}

.device-code strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.note {
  margin-top: 16px;
  max-width: 760px;
  line-height: 1.5;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10;
  width: min(700px, calc(100% - 24px));
  justify-content: center;
  gap: 4px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(29, 27, 24, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.floating-refresh {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 12;
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 999px;
  background: rgba(47, 111, 150, 0.94);
  color: #fff;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(14px);
}

.floating-refresh:hover {
  background: #347ca8;
}

:root[data-theme="light"] .bottom-nav {
  background: rgba(255, 255, 255, 0.93);
}

.nav-item {
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  width: 72px;
  min-height: 52px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
}

.nav-item.active {
  border-radius: 18px;
  background: var(--surface-3);
  color: var(--ink);
}

.nav-plus svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 980px) {
  .quick-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-card {
    grid-template-columns: minmax(0, 1fr) 118px 98px;
  }

  .record-person,
  .record-date,
  .record-balance,
  .record-actions {
    grid-column: 1 / -1;
  }

  .record-actions {
    justify-content: flex-start;
  }

  .timeline-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 98px;
  }

  .app-shell {
    padding: 7px 7px 18px;
  }

  .hero {
    padding: 16px 14px;
  }

  .brand-row,
  .panel-head,
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .hero-actions {
    justify-content: flex-end;
  }

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

  .view {
    margin-top: 14px;
  }

  .panel {
    padding: 16px;
    border-radius: 18px;
  }

  .quick-form,
  .list-tools,
  .report-tools,
  .settings-grid,
  .license-line,
  .backup-actions,
  .cloud-line,
  .detail-row {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .form-actions button {
    width: 100%;
  }

  .record-card {
    grid-template-columns: 1fr;
  }

  .record-actions {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
  }

  .action-button {
    width: 100%;
  }

  .tool-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .soft-button {
    padding: 0 8px;
  }

  .bottom-nav {
    justify-content: space-between;
    gap: 1px;
    overflow-x: hidden;
  }

  .floating-refresh {
    right: 14px;
    bottom: calc(96px + env(safe-area-inset-bottom));
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .nav-item {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    font-size: 0.62rem;
  }

  .nav-item svg {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 520px) {
  .settings-card {
    grid-template-columns: 1fr;
    align-items: stretch;
    min-height: 0;
    gap: 12px;
    padding: 14px;
  }
}

@media (max-width: 420px) {
  .brand-title {
    align-items: flex-start;
  }

  .brand-logo {
    width: 42px;
    height: 42px;
  }

  .metric {
    padding: 10px;
  }

  .metric strong {
    font-size: 1rem;
  }
}
