:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --fg: #e8e8ea;
  --muted: #9a9ba3;
  --accent: #5b8cff;
  --border: #2a2d36;
  --error: #ff6b6b;
  --panel: #171921;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

/* --- Landing page (index.html) ------------------------------------------ */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

h1 {
  margin-top: 0;
}

.pitch {
  color: var(--muted);
  font-size: 1.05rem;
}

.button {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
}

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

.plans-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.plans-section h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.plans-table th:nth-child(2),
.plans-table th:nth-child(3),
.plans-table td:nth-child(2),
.plans-table td:nth-child(3) {
  text-align: center;
}

.plans-table th:first-child,
.plans-table td:first-child {
  color: var(--muted);
}

.limits-list {
  margin: 0 0 0.5rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.limits-list li {
  margin-bottom: 0.5rem;
}

/* --- Dashboard shell: full-width topbar + sidebar + main ---------------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-brand {
  font-weight: 700;
  font-size: 1.1rem;
}

.topbar-spacer {
  flex: 1;
}

.topbar-email {
  color: var(--muted);
  font-size: 0.9rem;
}

.checkout-message {
  padding: 0.5rem 1.5rem 0;
  margin: 0;
}

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.sidebar-new-button {
  width: 100%;
  align-self: stretch;
  margin-bottom: 1rem;
}

.projects-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.project-item {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  border: 1px solid transparent;
  font-weight: 400;
}

.project-item:hover {
  background: var(--panel);
  filter: none;
}

.project-item.active {
  background: var(--panel);
  border-color: var(--accent);
}

.project-item .name {
  font-weight: 600;
  font-size: 0.9rem;
}

.project-item .subdomain {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem;
  overflow-y: auto;
}

.empty-state {
  color: var(--muted);
  padding: 4rem 0;
  text-align: center;
}

.project-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.project-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.project-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.9rem;
  margin: 0 0 1.75rem;
}

.project-meta dt {
  color: var(--muted);
}

.project-meta dd {
  margin: 0;
}

@media (max-width: 720px) {
  .app-body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* --- Shared table/hint/form/button styles -------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--panel);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: -0.5rem;
}

.plan-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

#upgrade-button {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-width: 420px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  font-size: 0.95rem;
}

.subdomain-input {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.subdomain-input input {
  flex: 1;
}

.subdomain-input span {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

button {
  align-self: flex-start;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.1);
}

.error {
  color: var(--error);
  font-size: 0.9rem;
}

/* --- Dialogs (create-project-modal, delivery-modal) ---------------------- */

dialog {
  width: min(640px, 90vw);
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.icon-button {
  align-self: auto;
  padding: 0.1rem 0.5rem;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
}

.icon-button:hover {
  color: var(--fg);
  filter: none;
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(85vh - 60px);
}

.modal-body h4 {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.delivery-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  margin: 0;
  font-size: 0.9rem;
}

.delivery-summary dt {
  color: var(--muted);
}

.delivery-summary dd {
  margin: 0;
}

#delivery-headers-table td {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

#delivery-headers-table td:first-child {
  color: var(--muted);
  white-space: nowrap;
  width: 1%;
  padding-right: 1rem;
}

#delivery-payload {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}

/* --- Volume chart --------------------------------------------------------- */

.chart-controls {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.range-button {
  align-self: auto;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
}

.range-button:hover {
  filter: none;
  color: var(--fg);
}

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

.volume-chart {
  display: block;
  width: 100%;
  height: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.volume-chart rect {
  fill: var(--accent);
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 560px) {
  .stat-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
