/* Ops Platform R1 UI — simple modern, mobile-first */

:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #e2e8ef;
  --accent: #0f6e6a;
  --accent-soft: #e6f4f3;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --shadow: 0 1px 2px rgba(26, 35, 50, 0.06), 0 8px 24px rgba(26, 35, 50, 0.06);
  --radius: 14px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "DM Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --display: "Fraunces", "Songti SC", "STSong", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

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

.hidden { display: none !important; }

/* ----- Login ----- */
#view-login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, #d7ebe9 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, #e8eef5 0%, transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.login-card .brand {
  font-family: var(--display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.login-card .sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 28px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fafbfc;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}
.field textarea { min-height: 88px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, opacity .12s, background .12s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: #0c5c59; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-soft {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn-sm { padding: 8px 12px; font-size: 0.875rem; border-radius: 8px; }
.btn-block { width: 100%; }

.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0 0 12px;
  min-height: 1.2em;
}

/* ----- Shell ----- */
#app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
}

@media (min-width: 900px) {
  #app-shell {
    flex-direction: row;
    padding-bottom: 0;
    min-height: 100vh;
  }
}

.sidebar {
  display: none;
}

@media (min-width: 900px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 28px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .sidebar .brand {
    font-family: var(--display);
    font-size: 1.35rem;
    font-weight: 600;
    margin: 0 12px 4px;
  }
  .sidebar .brand-sub {
    color: var(--muted);
    font-size: 0.8rem;
    margin: 0 12px 28px;
  }
  .sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }
  .sidebar .nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
  }
  .sidebar .user-box {
    border-top: 1px solid var(--line);
    padding-top: 16px;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--muted);
  }
}

.main {
  flex: 1;
  min-width: 0;
  padding: 16px 16px 8px;
}

@media (min-width: 900px) {
  .main { padding: 28px 32px 40px; max-width: 1100px; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar h1 {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.topbar .meta { color: var(--muted); font-size: 0.85rem; }

@media (min-width: 900px) {
  .topbar-mobile-only { display: none; }
}

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 40;
}
.bottom-nav button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .ico { font-size: 1.15rem; line-height: 1; }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
}

/* Cards / grids */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .stats.stats-6 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1100px) {
  .stats.stats-6 { grid-template-columns: repeat(6, 1fr); }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.stat .value {
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: -0.03em;
}
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-hd h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.panel-bd { padding: 8px 0; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #f8fafb; }
.list-item .title { font-weight: 650; margin: 0 0 2px; }
.list-item .desc { color: var(--muted); font-size: 0.82rem; margin: 0; }
.list-item .chev { margin-left: auto; color: #9aa8b5; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2f6;
  color: var(--muted);
}
.badge.awaiting_order_id { background: #eef2f6; }
.badge.awaiting_grant { background: var(--warn-soft); color: var(--warn); }
.badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.refund_pending_revoke { background: var(--danger-soft); color: var(--danger); }
.badge.closed { background: #f1f5f9; color: #64748b; }

/* Activation spotlight */
.activate-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -4px 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0f6e6a 0%, #145a72 100%);
  color: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.activate-bar p { margin: 0; font-size: 0.88rem; opacity: 0.92; }
.activate-bar strong { display: block; font-size: 1.05rem; margin-bottom: 2px; }
.activate-bar .btn {
  background: #fff;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.queue-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.queue-tabs button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 650;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.queue-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.queue-tabs .count {
  margin-left: 4px;
  opacity: 0.85;
}

/* Customer detail */
.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 18px;
}
.detail-actions .btn-activate {
  grid-column: 1 / -1;
  background: var(--accent);
  color: #fff;
  padding: 16px;
  font-size: 1.05rem;
  border-radius: 12px;
}
.kv {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px 12px;
  padding: 4px 16px 16px;
  font-size: 0.92rem;
}
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; word-break: break-all; }

.notes { padding: 0 16px 16px; }
.note {
  background: #f8fafb;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.note time { display: block; color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }

/* Cost cards */
.cost-grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 700px) {
  .cost-grid { grid-template-columns: repeat(3, 1fr); }
}
.cost-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.cost-card .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.cost-card h3 { margin: 0; font-size: 1rem; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
}
.dot.green { background: var(--ok); }
.dot.yellow { background: #d97706; }
.dot.red { background: var(--danger); }
.cost-card .balance {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 8px 0;
}
.cost-card .err {
  color: var(--danger);
  font-size: 0.8rem;
  margin: 0;
}
.cost-card .ts { color: var(--muted); font-size: 0.75rem; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 24px;
  }
}
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 440px;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}
@media (min-width: 600px) {
  .modal { border-radius: 16px; padding: 24px; }
}
.modal h3 { margin: 0 0 8px; font-family: var(--display); }
.modal .hint { color: var(--muted); font-size: 0.88rem; margin: 0 0 16px; }
.modal .actions { display: flex; gap: 10px; margin-top: 8px; }
.modal .actions .btn { flex: 1; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar input {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: 90vw;
}
@media (min-width: 900px) {
  .toast { bottom: 28px; }
}
.toast.show { opacity: 1; }

.back-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  margin-bottom: 8px;
}
