/* AppSite Subscriptions — Subscriber management & recurring billing */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ed;
  --text: #1a2332;
  --text-muted: #6b7a8f;
  --primary: #0f766e;
  --primary-hover: #0d6460;
  --primary-light: #edf7f6;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 8px;
  --sidebar-w: 220px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 28px;
}

/* topnav injects a header before .workspace; let flex handle the remaining height */
body:has(#appsite-topnav) .workspace { height: auto !important; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
header.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; flex-shrink: 0; }
header.topbar h1 { font-size: 18px; font-weight: 700; }
header.topbar .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ── Workspace / Layout ───────────────────────────────────────────────────── */
.workspace { padding: 12px; display: flex; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
/* ── Order list (left panel) ──────────────────────────────────────────────── */
.order-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius,8px); overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }
.order-list-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.order-list-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.order-item { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; color: var(--text); }
.order-item:hover { background: var(--bg); }
.order-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.order-item.plan-inactive { opacity: 0.6; }
.order-item:last-child { border-bottom: 0; }

/* ── Order editor (right panel) ───────────────────────────────────────────── */
.order-editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius,8px); display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

/* ── Workspace title (inside order-editor) ────────────────────────────────── */
.workspace-title { font-size: 15px; font-weight: 700; }
.workspace-subtitle { font-size: 12px; color: var(--text-muted); }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--text); }
.card-body { padding: 0; }

/* ── Summary cards ────────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.summary-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 4px; }
.summary-value { font-size: 20px; font-weight: 700; color: var(--text); }
.summary-value.positive { color: var(--success); }
.summary-value.negative { color: var(--danger); }

/* ── Table ────────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  padding: 9px 14px;
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); background: var(--bg);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.amount-debit { color: var(--text); }
.amount-credit { color: var(--success); }

/* ── Status badges ────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-warning { background: #fef9c3; color: #92400e; }
.badge-danger  { background: var(--danger-light); color: var(--danger); }

.event-type-badge {
  display: inline-block; padding: 2px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
  background: var(--bg); color: var(--text-muted);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button { font-family: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  border: 1px solid transparent; transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-surface { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-surface:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; padding: 5px 8px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 12px; }
.form-grid.two   { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
label.checkbox-field { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
label.checkbox-field input { width: auto; }
.field-input, input[type="text"], input[type="number"], input[type="email"],
input[type="date"], input[type="search"], select, textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: inherit; color: var(--text); background: var(--surface);
  outline: none; transition: border-color 0.15s; width: 100%;
}
.field-input:focus, input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
.field-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 560px; max-width: 100%; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.modal-wide { width: 680px; }
.modal-header {
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--bg); }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { padding: 12px 20px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Status bar ───────────────────────────────────────────────────────────── */
#statusBar {
  padding: 6px 16px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
}
#statusBar.error { color: var(--danger); background: var(--danger-light); }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 13px; }

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Landing page (index.html) ────────────────────────────────────────────── */
.landing-wrap { max-width: 900px; margin: 0 auto; padding: 48px 24px 32px; }
.landing-hero { margin-bottom: 40px; }
.landing-hero h1 { margin: 0 0 10px; font-size: 28px; }
.landing-sub { color: var(--text-muted); font-size: 16px; margin-top: 6px; max-width: 520px; }
.landing-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 24px; }
.btn-signin { display: inline-block; padding: 10px 28px; background: var(--primary); color: #fff; border-radius: 8px; font-size: 15px; font-weight: 700; text-decoration: none; }
.btn-signin:hover { background: var(--primary-hover); }
.btn-hub { display: inline-block; padding: 10px 20px; background: transparent; color: var(--text-muted); border-radius: 8px; font-size: 14px; font-weight: 600; text-decoration: none; border: 1px solid var(--border); }
.btn-hub:hover { border-color: var(--primary); color: var(--primary); }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px 18px; }
.feature-card svg { width: 26px; height: 26px; stroke: var(--primary); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; margin-bottom: 12px; }
.feature-card h3 { margin: 0 0 4px; font-size: 14px; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: 13px; }
.landing-footer { text-align: center; padding: 24px 16px; font-size: 12px; color: var(--text-muted); }
.landing-footer a { color: inherit; text-decoration: underline; }

/* ── SSO banner (landing page) ────────────────────────────────────────────── */
.sso-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.sso-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--border); }
.sso-name { font-weight: 600; font-size: 14px; flex: 1; }
.sso-actions { display: flex; align-items: center; gap: 8px; }
.btn-link { font-size: 13px; font-weight: 600; color: var(--text-muted); text-decoration: none; }
.btn-link:hover { color: var(--text); }
.btn-sm { min-height: unset; padding: 5px 12px; font-size: 12px; font-family: inherit; font-weight: 600; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.btn-sm:hover { background: var(--border); }

@media print {
  .order-list, header.topbar, #appsite-topnav { display: none !important; }
  body { height: auto; overflow: visible; }
  .workspace { overflow: visible; }
}
