:root {
  --environment-banner-height: 56px;
  --bg: #f5f7f6;
  --panel: #ffffff;
  --line: #d9e1dd;
  --text: #1c2621;
  --muted: #65736d;
  --primary: #137a5b;
  --primary-dark: #0e5c45;
  --accent: #b3452c;
  --warn: #b7791f;
  --danger: #b42318;
  --ok: #087443;
  --field: #ffffff;
  --table-head: #edf3f0;
  --sidebar-bg: #10241d;
  --sidebar-text: #eef8f4;
  --sidebar-muted: #aac0b7;
  --topbar-bg: rgba(245, 247, 246, 0.94);
  --button-bg: #ffffff;
  --hover-line: #b8c6c0;
  --shadow: 0 10px 30px rgba(18, 38, 30, 0.08);
}

body.theme-dark {
  --bg: #101815;
  --panel: #17231f;
  --line: #2d4038;
  --text: #edf7f3;
  --muted: #9eb4ab;
  --primary: #1ca67c;
  --primary-dark: #14835f;
  --accent: #f08a67;
  --warn: #f0b84f;
  --danger: #ff7b72;
  --ok: #62d394;
  --field: #111c18;
  --table-head: #20342d;
  --sidebar-bg: #07130f;
  --sidebar-text: #f3fbf8;
  --sidebar-muted: #8faaa0;
  --topbar-bg: rgba(16, 24, 21, 0.94);
  --button-bg: #16231f;
  --hover-line: #4a6258;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-top: var(--environment-banner-height);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.environment-banner {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  min-height: var(--environment-banner-height);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  text-align: center;
  color: #5f3600;
  background: #fff2c2;
  border-bottom: 1px solid #e0b85b;
  box-shadow: 0 4px 16px rgba(95, 54, 0, 0.12);
}

.environment-banner[hidden] {
  display: none !important;
}

.environment-banner strong {
  font-size: 0.9rem;
}

.environment-banner span {
  font-size: 0.88rem;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 76px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 18px;
  position: sticky;
  top: var(--environment-banner-height);
  height: calc(100vh - var(--environment-banner-height));
  overflow: hidden;
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-text {
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #eef8f4;
  color: #10241d;
  display: grid;
  place-items: center;
  font-weight: 800;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand small {
  display: block;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  color: #dbe9e3;
  background: transparent;
  text-align: left;
  padding: 11px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.main {
  min-width: 0;
}

.nav-icon,
.inline-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-icon svg,
.inline-icon svg,
.sidebar-toggle svg,
.icon-button svg {
  width: 100%;
  height: 100%;
  display: block;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-inline: 12px;
}

.app-shell.sidebar-collapsed .brand {
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-label {
  display: none;
}

.app-shell.sidebar-collapsed .nav-item,
.app-shell.sidebar-collapsed .sidebar-toggle {
  justify-content: center;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 24px 28px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: var(--environment-banner-height);
  z-index: 3;
  backdrop-filter: blur(8px);
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.period-filter,
.toolbar,
.form-grid,
.filters {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.user-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--field);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

.button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 12px;
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.button:hover {
  border-color: var(--hover-line);
}

.icon-button {
  width: 42px;
  padding: 8px;
  display: inline-grid;
  place-items: center;
}

.button.primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.danger {
  color: var(--danger);
}

.content {
  padding: 28px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi,
.panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  padding: 16px;
}

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.kpi small {
  color: var(--muted);
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  background: var(--panel);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: var(--table-head);
  font-size: 12px;
  color: var(--text);
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--table-head);
}

.status.ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, transparent);
}

.status.warn {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 16%, transparent);
}

.status.danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.status.muted {
  color: var(--muted);
}

.form-panel {
  padding: 18px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.form-grid .wide {
  grid-column: span 2;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

.tab.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 18px;
}

.dre-line {
  display: grid;
  grid-template-columns: 1fr 130px 100px;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.dre-line strong {
  font-weight: 800;
}

.dre-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 2px solid #bfccc6;
  font-weight: 800;
}

.empty-state {
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.actions {
  display: flex;
  gap: 8px;
}

.notice {
  border-left: 4px solid var(--accent);
  padding: 12px 14px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--text);
  border-radius: 8px;
  margin-bottom: 18px;
}

.login-layer {
  position: fixed;
  inset: var(--environment-banner-height) 0 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 0;
  z-index: 10;
  overflow: auto;
}

.login-layer[hidden] {
  display: none !important;
}

.login-theme-toggle {
  position: fixed;
  top: calc(var(--environment-banner-height) + 22px);
  right: 22px;
  z-index: 11;
}

.login-hero {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 560px);
  background: var(--panel);
}

.login-visual {
  min-height: 100vh;
  display: flex;
  align-items: flex-end;
  padding: 56px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(16, 36, 29, 0.94), rgba(19, 122, 91, 0.82)),
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.22), transparent 28%),
    linear-gradient(45deg, #10241d, #137a5b);
}

.login-visual-content {
  max-width: 460px;
  display: grid;
  gap: 12px;
}

.login-preview {
  width: min(360px, 100%);
  min-height: 160px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px;
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.login-preview span,
.login-preview strong,
.login-preview em {
  display: block;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
}

.login-preview span {
  width: 44%;
  height: 12px;
  margin-bottom: 22px;
}

.login-preview strong {
  width: 72%;
  height: 34px;
  margin-bottom: 14px;
}

.login-preview em {
  width: 58%;
  height: 12px;
  opacity: 0.72;
}

.login-visual-content strong {
  font-size: clamp(32px, 4vw, 54px);
  line-height: 1;
}

.login-visual-content > span:not(.brand-mark) {
  color: rgba(255, 255, 255, 0.78);
  font-size: 18px;
}

.login-brand-mark {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.92);
}

.login-box {
  width: min(440px, calc(100% - 48px));
  align-self: center;
  justify-self: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}

.login-form-mark {
  flex: 0 0 auto;
}

.login-box p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-help {
  color: var(--muted);
  font-size: 13px;
  background: var(--table-head);
  border-radius: 8px;
  padding: 10px;
}

.form-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
}

.logo-preview {
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--table-head);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-weight: 800;
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.report-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--table-head);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
}

.report-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.report-logo {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: var(--field);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-weight: 800;
}

.report-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.purchase-items,
.purchase-installments {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.items-table {
  min-width: 980px;
}

.items-table input {
  width: 100%;
  min-width: 96px;
}

.items-table td:first-child input {
  min-width: 220px;
}

.purchase-total {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  font-size: 18px;
}

.highlight-row td {
  background: color-mix(in srgb, var(--warn) 14%, var(--panel));
  box-shadow: inset 0 0 0 9999px rgba(183, 121, 31, 0.08);
}

.purchase-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  margin-bottom: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px 14px;
  margin-bottom: 14px;
  color: var(--muted);
}

.detail-grid strong {
  color: var(--text);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #f0fdf4;
}

.muted-text {
  color: var(--muted);
  font-size: 0.85rem;
}

@media print {
  .sidebar,
  .environment-banner,
  .topbar,
  .button,
  .tabs,
  .form-panel {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .content {
    padding: 0;
  }

  .panel {
    box-shadow: none;
    border: 0;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .login-hero {
    grid-template-columns: 1fr;
  }

  .login-visual {
    min-height: 260px;
    padding: 32px;
    align-items: center;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .topbar,
  .two-col {
    grid-template-columns: 1fr;
    display: grid;
  }

  .kpi-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --environment-banner-height: 82px;
  }

  .environment-banner {
    flex-direction: column;
    gap: 2px;
    padding: 8px 14px;
  }

  .content,
  .topbar {
    padding: 18px;
  }

  .login-box {
    width: calc(100% - 32px);
    padding: 22px;
  }

  .login-visual {
    min-height: 210px;
    padding: 24px;
  }

  .kpi-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: span 1;
  }
}
