:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #dfe6ef;
  --text: #182235;
  --muted: #66758a;
  --soft: #eef3f8;
  --primary: #1f6feb;
  --primary-dark: #1859bd;
  --green: #14945b;
  --red: #d43f3a;
  --amber: #b7791f;
  --shadow: 0 14px 36px rgba(24, 34, 53, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 111, 235, .12), rgba(20, 148, 91, .10)),
    #f6f9fd;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #e8f1ff;
  color: var(--primary);
  font-weight: 800;
  font-size: 24px;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 19px;
}

.login-panel h1 {
  margin: 22px 0 6px;
  font-size: 28px;
}

.login-panel p {
  margin: 0 0 28px;
  color: var(--muted);
}

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

label, .field-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--text);
  padding: 9px 12px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}

.primary-btn, .secondary-btn, .danger-btn, .text-btn, .link-btn {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 16px;
  font-weight: 650;
}

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

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

.secondary-btn {
  background: #eef3f8;
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary-btn.small {
  min-height: 34px;
  margin-top: 10px;
}

.danger-btn {
  min-height: 30px;
  padding: 0 10px;
  background: #fff1f0;
  color: var(--red);
}

.text-btn, .link-btn {
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.form-message {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #111827;
  color: #fff;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 22px 16px;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 22px;
}

.sidebar-brand span {
  display: block;
  margin-top: 3px;
  color: #9ca3af;
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 8px;
  align-content: start;
}

.nav-btn {
  border: 0;
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0 14px;
}

.nav-btn.active {
  background: #253044;
  color: #fff;
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.12);
  padding-top: 16px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  color: #cbd5e1;
}

.sidebar-footer span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
}

.quick-actions, .toolbar, .filters, .modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.filters {
  flex-wrap: wrap;
}

.filters select, .filters input {
  width: auto;
  min-width: 150px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

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

.stat-card, .content-panel, .summary-strip, .record-card, .comparison-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(24, 34, 53, .05);
}

.stat-card {
  padding: 18px;
}

.stat-card span, .summary-strip span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.stat-card.urgent strong {
  color: var(--red);
}

.content-panel {
  padding: 18px;
}

.content-panel.narrow {
  max-width: 520px;
}

.content-panel h3 {
  margin: 0 0 16px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel-title h3 {
  margin: 0;
}

.record-list, .comparison-list {
  display: grid;
  gap: 10px;
}

.record-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}

.record-card > div:first-of-type {
  flex: 1;
  min-width: 0;
}

.record-card strong {
  display: block;
  font-size: 15px;
}

.record-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.record-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.pay-color { color: var(--primary); }
.invoice-color { color: var(--green); }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.summary-strip strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.comparison-card {
  display: grid;
  grid-template-columns: 1fr repeat(3, auto);
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
}

.comparison-card span {
  color: var(--muted);
}

.comparison-card b {
  color: var(--red);
}

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

.empty-icon {
  font-size: 34px;
  margin-bottom: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .48);
  z-index: 20;
}

.modal.active {
  display: grid;
}

.modal-content {
  width: min(460px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
}

.modal-close {
  background: transparent;
  border: 0;
  font-size: 24px;
  color: var(--muted);
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

.file-upload-area {
  min-height: 92px;
  display: grid;
  place-items: center;
  border: 1px dashed #b8c3d2;
  border-radius: 10px;
  background: #f8fbfe;
  color: var(--muted);
}

.file-preview img {
  max-width: 210px;
  max-height: 150px;
  border-radius: 8px;
  display: block;
  margin-bottom: 6px;
}

.invoice-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
}

.file-link {
  color: var(--primary);
  text-decoration: none;
}

.mobile-nav {
  display: none;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    padding-bottom: 64px;
  }

  .sidebar {
    position: static;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
  }

  .sidebar-brand {
    flex: 1;
    min-width: 0;
    padding-bottom: 0;
  }

  .sidebar-brand strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar-footer {
    flex: 0 0 auto;
    border-top: 0;
    padding-top: 0;
  }

  .side-nav {
    display: none;
  }

  .sidebar-brand span {
    display: none;
  }

  .workspace {
    padding: 18px 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .quick-actions {
    display: none;
  }

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

  .toolbar {
    display: grid;
  }

  .filters {
    display: grid;
  }

  .filters select, .filters input {
    width: 100%;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .comparison-card {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--line);
    z-index: 10;
  }

  .mobile-nav .nav-btn {
    color: var(--muted);
    text-align: center;
    border-radius: 0;
  }

  .mobile-nav .nav-btn.active {
    background: #e8f1ff;
    color: var(--primary);
  }
}
