:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --panel-2: #232d39;
  --line: #314050;
  --text: #e8eef4;
  --muted: #93a4b5;
  --accent: #f5a524;
  --ok: #3ecf8e;
  --danger: #ef6b6b;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(1200px 500px at 10% -10%, #243140 0%, var(--bg) 55%);
  color: var(--text);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(10px);
}

.brand { font-weight: 700; letter-spacing: 0.02em; }
.brand span { color: var(--accent); }

.nav { display: flex; gap: 1rem; align-items: center; }
.nav a, .nav button { color: var(--muted); background: none; border: 0; cursor: pointer; font: inherit; }
.nav a.active, .nav a:hover { color: var(--text); }

.wrap { width: min(1180px, calc(100% - 2rem)); margin: 1.5rem auto 3rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

h1 { font-size: 1.5rem; margin: 0 0 0.35rem; }
.lead { color: var(--muted); margin: 0 0 1.25rem; }

.store-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.store-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.store-chip input { accent-color: var(--accent); }
.store-chip.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip-only { font-size: 0.75rem; color: var(--muted); }
.chip-only:hover { color: var(--accent); }

.queue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  margin: 0 0 1.5rem;
}

.queue-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.queue-card h3 { margin: 0 0 0.2rem; font-size: 1rem; }

.queue-link {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  color: var(--muted);
  padding: 0.35rem 0;
}
.queue-link.warn { color: var(--accent); font-weight: 600; }
.queue-count {
  min-width: 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}
.queue-link.warn .queue-count { color: var(--accent); }
.queue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}
.queue-actions .btn { padding: 0.3rem 0.55rem; font-size: 0.8rem; }

.thread-head { margin-bottom: 0.55rem; }
.thread-title { margin: 0 0 0.2rem; font-size: 1.05rem; }
.reconcile-ml_only td:first-child,
.reconcile-mp_only td:first-child { color: var(--accent); font-weight: 600; }
.reconcile-matched td:first-child { color: var(--ok); }

.period-filter { position: relative; margin-bottom: 1.25rem; }
.periods { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.period-custom-popover {
  display: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 30;
  min-width: min(100%, 20rem);
  padding: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.period-custom-popover.open { display: block; }
.period-custom-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
}
.period-range-calendar .flatpickr-calendar {
  margin: 0 auto;
  box-shadow: none;
}
.period-range-summary {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}
.period-refresh { flex-shrink: 0; }
.periods button, .btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font: inherit;
}
.periods button.on, .btn-primary { background: var(--accent); color: #1b1408; border-color: var(--accent); font-weight: 700; }
.btn-danger { background: #4a2323; border-color: var(--danger); color: #ffd6d6; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.25rem;
}

.kpi { background: var(--panel-2); border-radius: 14px; padding: 1rem; border: 1px solid var(--line); }
.kpi .label { color: var(--muted); font-size: 0.82rem; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 0.25rem; }
.kpi.warn .value { color: var(--accent); }
.kpi-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--accent);
}
.period-limit-notice {
  grid-column: 1 / -1;
  padding: 0.7rem 0.95rem;
  border-radius: 10px;
  background: #3a2f14;
  border: 1px solid var(--accent);
}
.period-limit-notice .kpi-hint { color: #f5d9a8; }

table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.72rem; font-weight: 600; }

.notice { background: #1d3b2d; color: #c8f5dc; padding: 0.7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.error { background: #3b1d1d; color: #ffd0d0; padding: 0.7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.muted { color: var(--muted); }
.empty { padding: 2rem 0; text-align: center; color: var(--muted); }
.page-loading {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
  margin-top: 1rem;
  animation: page-pulse 1.2s ease-in-out infinite;
}
@keyframes page-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.page-data { margin-top: 0.5rem; }

.login-box { width: min(420px, calc(100% - 2rem)); margin: 12vh auto; }
input[type="password"],
input[type="text"],
input[type="email"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  box-sizing: border-box;
}

input[type="password"]:focus,
input[type="text"]:focus,
input[type="email"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 165, 36, 0.15);
}
.row { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.tiny { font-size: 0.8rem; color: var(--muted); }

.thread-list { display: flex; flex-direction: column; gap: 0.9rem; }
.thread-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}
.thread-text { margin: 0 0 0.4rem; white-space: pre-wrap; }

textarea {
  width: 100%;
  min-height: 5.5rem;
  margin: 0.6rem 0 0.25rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.char-count { margin: 0 0 0.7rem; }
.char-count.limit { color: var(--accent); }

.creds-form label,
.creds-field label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}
.creds-form,
.creds-form .creds-field {
  display: grid;
  gap: 0.3rem;
}
.creds-form {
  gap: 0.7rem;
  margin: 0 0 1.4rem;
}
.creds-form input[type="password"],
.creds-form .secret-field input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.secret-field {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
}
.secret-field input {
  flex: 1;
  min-width: 0;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  min-width: 2.35rem;
}
.btn-icon svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.secret-toggle .icon-eye-off { display: none; }
.secret-toggle.is-visible .icon-eye { display: none; }
.secret-toggle.is-visible .icon-eye-off { display: block; }

.store-actions { min-width: 12rem; white-space: nowrap; }
.store-actions-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.store-actions-inner form {
  display: inline-flex;
  margin: 0;
}

.bubbles { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.bubble {
  max-width: min(36rem, 92%);
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble.mine { align-self: flex-end; background: #3a2a12; border-color: var(--accent); }
.bubble.theirs { align-self: flex-start; background: var(--panel-2); }

.warn-card { border-color: var(--accent); }
input[type="file"] {
  width: 100%;
  margin: 0.6rem 0 0.8rem;
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: minmax(12rem, 1.6fr) repeat(4, minmax(8rem, 1fr)) auto;
  gap: 0.6rem;
  align-items: end;
  margin: 0 0 1rem;
}
.filter-field {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.filter-field input,
.filter-field select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.filter-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.order-date {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  white-space: nowrap;
}
.order-date-day { font-weight: 600; }
.order-date-time { font-size: 0.78rem; color: var(--muted); }
.order-id { font-variant-numeric: tabular-nums; }
.badge-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-ok { background: #1d3b2d; color: #c8f5dc; }
.badge-warn { background: #3b2e12; color: #ffd89a; }
.badge-info { background: #1c3147; color: #9ec9f0; }
.badge-danger { background: #3b1d1d; color: #ffd0d0; }
.badge-muted { background: #243040; color: #93a4b5; }
.orders-pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  margin-top: 1rem;
}
.page-size,
.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.page-size > span,
.page-indicator {
  color: var(--muted);
  font-size: 0.82rem;
}
@media (max-width: 980px) {
  .filters { grid-template-columns: 1fr 1fr; }
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin: 0 0 1.5rem;
}
.chart-card {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: linear-gradient(165deg, rgba(40, 52, 66, 0.55) 0%, rgba(26, 34, 44, 0.95) 48%, rgba(20, 27, 35, 1) 100%);
  border: 1px solid rgba(49, 64, 80, 0.85);
  border-radius: 16px;
  padding: 1rem 1rem 0.85rem;
  box-shadow: var(--shadow);
}
.chart-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), rgba(245, 165, 36, 0.15) 70%, transparent);
  opacity: 0.85;
}
.chart-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 250px;
  margin-top: auto;
}
.chart-wrap canvas {
  display: block;
}

.landing-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 22, 28, 0.85);
  backdrop-filter: blur(8px);
}

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

.landing-brand span {
  color: var(--accent);
}

.landing-nav {
  display: flex;
  gap: 0.75rem;
}

.landing-main {
  flex: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  width: 100%;
}

.landing-hero {
  text-align: center;
  padding: 2.5rem 2rem;
  margin-bottom: 2.5rem;
}

.landing-kicker {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 0.75rem;
}

.landing-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  margin: 0 0 1rem;
  line-height: 1.2;
}

.landing-cta {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.landing-section {
  margin-bottom: 2.5rem;
}

.landing-section h2 {
  margin: 0 0 1.25rem;
  font-size: 1.35rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.feature-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--accent);
}

.feature-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.benefit-list {
  list-style: none;
  margin: 0;
  padding: 1.25rem 1.5rem;
}

.benefit-list li {
  padding: 0.5rem 0 0.5rem 1.5rem;
  position: relative;
  color: var(--muted);
}

.benefit-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--ok);
  font-weight: 700;
}

.landing-footer {
  text-align: center;
  padding: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-box {
  max-width: 420px;
  margin: 4rem auto;
  padding: 2rem;
}

.auth-box form p {
  margin: 0 0 1rem;
}

.auth-box label.tiny {
  display: block;
  margin-bottom: 0.35rem;
}

.auth-box input[type="email"],
.auth-box input[type="password"],
.auth-box input[type="text"] {
  width: 100%;
}

.auth-box .btn-primary {
  width: 100%;
  margin-top: 0.25rem;
}

.auth-box h1 {
  margin: 0.5rem 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-switch {
  margin-top: 1.25rem;
  text-align: center;
}

.btn-google {
  display: block;
  text-align: center;
  width: 100%;
}

.login-box {
  max-width: 420px;
  margin: 4rem auto;
  padding: 2rem;
}

.reconnect-banner {
  padding-top: 1rem;
}

.reconnect-banner .notice.warn {
  margin-bottom: 0.5rem;
  border-color: var(--accent);
}

.dce-banner {
  margin-bottom: 1rem;
}

.dce-deadline-urgent {
  color: #ffb4b4;
  font-weight: 600;
}

.dce-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.cell-actions .btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

.orders-table-wrap {
  overflow-x: auto;
  margin-bottom: 0.5rem;
}
