:root {
  --bg: #f4f8ff;
  --surface: #ffffff;
  --surface-2: #edf4ff;
  --text: #172a45;
  --muted: #657896;
  --line: #d8e5f7;
  --nav: #f8fbff;
  --nav-2: #eaf3ff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --blue: #2563eb;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #15803d;
  --shadow: 0 12px 30px rgba(24, 37, 47, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    linear-gradient(135deg, #e7f1ff, #f7fbff);
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(320px, 430px);
  width: min(940px, calc(100vw - 32px));
  min-height: 520px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.25);
}

.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 64px 52px;
  color: #fff;
  background:
    radial-gradient(circle at 80% 20%, rgba(147, 197, 253, 0.55), transparent 35%),
    linear-gradient(145deg, #2563eb, #60a5fa);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  font-size: 30px;
  background: rgba(255, 255, 255, 0.1);
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 21px;
}

.login-brand h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0;
}

.login-brand p {
  max-width: 420px;
  margin: 0;
  color: rgba(255, 255, 255, 0.76);
}

.eyebrow {
  margin-bottom: 8px;
  color: #dbeafe !important;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 52px 46px;
}

.login-heading h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-heading p {
  margin: 0;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  color: #334651;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  font-weight: 650;
}

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

.button svg {
  width: 17px;
  height: 17px;
}

.button-primary {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.button-primary:hover {
  background: var(--accent-hover);
}

.button-danger {
  border-color: #fecaca;
  color: var(--danger);
  background: #fff1f2;
}

.button-danger:hover {
  background: #ffe4e6;
}

.button-wide {
  width: 100%;
}

.form-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.admin-page {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 12px;
  color: var(--text);
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--nav), var(--nav-2));
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 22px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand strong,
.sidebar-brand span {
  display: block;
}

.sidebar-brand span {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-nav {
  display: grid;
  gap: 3px;
  padding-top: 20px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 11px;
  border: 0;
  border-radius: 6px;
  color: #50627c;
  text-align: left;
  background: transparent;
}

.nav-item:hover {
  color: var(--accent);
  background: #edf5ff;
}

.nav-item.active {
  color: var(--accent);
  background: #dbeafe;
}

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

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 18px 8px 2px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12);
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

#page-eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.08em;
}

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

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
}

.icon-button:hover {
  color: var(--text);
  background: var(--surface-2);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.page-content {
  width: min(1460px, 100%);
  min-height: calc(100vh - 84px);
  margin: 0 auto;
  padding: 26px 28px 48px;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 300px;
  color: var(--muted);
}

.loading-state svg {
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.toolbar h2 {
  margin: 0;
  font-size: 18px;
}

.toolbar-actions,
.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.filter-group input,
.filter-group select {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #fff;
}

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

.metric-card {
  min-height: 120px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(24, 37, 47, 0.04);
}

.metric-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.metric-label svg {
  width: 16px;
  height: 16px;
}

.metric-value {
  margin-top: 14px;
  font-size: 26px;
  font-weight: 750;
  letter-spacing: 0;
}

.metric-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(24, 37, 47, 0.04);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 18px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.data-table th {
  padding: 10px 12px;
  color: #546774;
  text-align: left;
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #edf2f4;
  color: #273944;
}

.data-table tbody tr:hover {
  background: #f7fafb;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.badge.active,
.badge.won,
.badge.settled {
  color: #166534;
  background: #dcfce7;
}

.badge.frozen,
.badge.pending {
  color: #92400e;
  background: #fef3c7;
}

.badge.archived,
.badge.lost {
  color: #64748b;
  background: #f1f5f9;
}

.badge.void {
  color: #991b1b;
  background: #fee2e2;
}

.money-positive {
  color: var(--success);
  font-weight: 700;
}

.money-negative {
  color: var(--danger);
  font-weight: 700;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions .button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(8, 19, 27, 0.54);
  backdrop-filter: blur(3px);
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
}

.modal-close:hover {
  background: var(--surface-2);
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.detail-item {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid #edf2f4;
}

.detail-item span:first-child {
  color: var(--muted);
}

.toast-root {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 44px));
}

.toast {
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  color: #fff;
  background: #243642;
  box-shadow: var(--shadow);
}

.toast.error {
  border-left-color: var(--danger);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
}

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

  .login-brand {
    padding: 42px;
  }

  .admin-page {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: block;
    height: auto;
  }

  .sidebar-nav {
    display: flex;
    overflow-x: auto;
    padding-top: 12px;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .sidebar-foot {
    display: none;
  }

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

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

@media (max-width: 620px) {
  .topbar,
  .page-content {
    padding-right: 16px;
    padding-left: 16px;
  }

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

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

  .topbar-actions {
    flex-direction: column;
  }

  .login-card {
    padding: 36px 24px;
  }
}
