:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ok-bg: #ecfdf5;
  --ok-text: #047857;
  --ok-border: #a7f3d0;
  --warn-bg: #fffbeb;
  --warn-text: #b45309;
  --warn-border: #fde68a;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --danger-border: #fecaca;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, #1e293b, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: grid;
  place-items: center;
  letter-spacing: 0.5px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rate-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 8px 5px 12px;
  box-shadow: var(--shadow);
}

.rate-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.rate-pill input {
  width: 74px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  text-align: right;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

.btn-link:hover {
  text-decoration: underline;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 15px;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.alert-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.alert-banner.urgent {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-warn .stat-value { color: #d97706; }
.stat-danger .stat-value { color: #dc2626; }
.stat-ok .stat-value { color: #059669; }

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

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.view-toggle {
  display: inline-flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 10px;
}

.view-btn {
  border: none;
  background: transparent;
  color: #475569;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
}

.view-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.grouped-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.client-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.client-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 18px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.client-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.client-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e0e7ff;
  color: #1d4ed8;
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.client-group-name {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
}

.client-group-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1 1 260px;
  max-width: 380px;
}

.search-wrap input {
  width: 100%;
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.filter-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.filter-tab:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

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

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #fafcff;
}

.client-name {
  font-weight: 600;
  color: var(--text);
}

.domain-link {
  display: inline-block;
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 2px;
}

.domain-link:hover {
  text-decoration: underline;
}

.meta-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-neutral {
  background: #f1f5f9;
  color: #334155;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid var(--ok-border);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.price-main {
  font-weight: 700;
  color: var(--text);
}

.price-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.price-est {
  font-size: 11.5px;
  color: #2563eb;
  margin-top: 2px;
}

.status-toggle {
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: opacity 0.15s;
}

.status-toggle:hover {
  opacity: 0.82;
}

.col-actions {
  text-align: right;
}

.action-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.mini-btn:hover {
  background: var(--surface-subtle);
  border-color: var(--border-strong);
}

.mini-btn.accent {
  color: var(--primary);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.mini-btn.accent:hover {
  background: #dbeafe;
}

.mini-btn.danger {
  color: #dc2626;
}

.mini-btn.danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

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

.footer {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

.footer code {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--text);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.modal-wide {
  max-width: 720px;
}

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

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

.modal-body {
  padding: 18px 20px 20px;
}

.modal-info {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-muted);
}

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

.form-grid.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.pricing-box {
  margin: 14px 0;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.pricing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.history-item.current {
  border-color: #93c5fd;
  background: #eff6ff;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
  z-index: 200;
}

.hidden {
  display: none !important;
}

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