/* ============================================================
   SHARED COMPONENTS
   Everything reused across 5+ pages.
   Load AFTER design-system.css.
   ------------------------------------------------------------
   Contents:
   - .layout (main grid)
   - .left-sidebar (220px)
   - .topbar (sticky top nav)
   - .btn, .btn-accent, .btn-secondary, .btn-ghost
   - .field-* (form inputs / labels / hints)
   - .filter-pill, .filter-tab
   - .stat-card, .action-bar, .tip-card
   - .modal, .toast (if needed)
   ============================================================ */

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  width: 100%;
}

.page-narrow { max-width: 800px; }
.page-medium { max-width: 1100px; }
.page-wide { max-width: 1400px; }

/* ============================================================
   LEFT SIDEBAR
   ============================================================ */
.left-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.ls-logo {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.ls-logo-mark {
  width: 28px;
  height: 28px;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
}
[data-theme="dark"] .ls-logo-mark { color: #0d0b07; }

.ls-collapse {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-3);
  padding: 4px;
  border-radius: 4px;
  font-size: 14px;
}

.ls-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.ls-group { margin-bottom: 16px; }

.ls-group-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  padding: 0 10px 6px;
}

.ls-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: none;
}
.ls-link:hover { background: var(--surface-2); color: var(--ink); }
.ls-link.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }

.ls-link-icon {
  font-size: 14px;
  width: 18px;
  display: inline-grid;
  place-items: center;
}

.ls-link-count {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--ink-4);
  font-family: 'JetBrains Mono', monospace;
}

.ls-link-badge {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--rust);
  color: #fff;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.ls-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
}

.ls-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
}

.ls-user-info { flex: 1; min-width: 0; }

.ls-user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ls-user-plan {
  font-size: 11px;
  color: var(--amber);
  font-family: 'JetBrains Mono', monospace;
}

.ls-user-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  color: var(--ink-3);
  font-size: 13px;
}
.ls-user-btn:hover { background: var(--bg); color: var(--ink); }

.ls-footer-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 4px 0;
  font-size: 10.5px;
  color: var(--ink-3);
  border-top: 1px solid var(--border-2);
  margin-top: 4px;
}
.ls-footer-links a { cursor: pointer; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.tb-search {
  flex: 1;
  max-width: 380px;
  position: relative;
}
.tb-search input {
  width: 100%;
  padding: 8px 14px 8px 34px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}
.tb-search input:focus { background: var(--bg); border-color: var(--accent); }
.tb-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 13px;
  pointer-events: none;
}

.tb-nav { display: flex; gap: 2px; }
.tb-nav a {
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}
.tb-nav a:hover { background: var(--surface); color: var(--ink); }
.tb-nav a.active { background: var(--accent-2); color: var(--accent); font-weight: 700; }

.tb-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto;
}

.tb-icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 15px;
  position: relative;
}
.tb-icon-btn:hover { background: var(--surface); color: var(--ink); }

.tb-icon-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  background: var(--rust);
  color: #fff;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  display: grid;
  place-items: center;
}

.tb-cta {
  padding: 7px 14px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
[data-theme="dark"] .tb-cta { color: #0d0b07; }

.tb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: transform 0.08s, background 0.1s, border-color 0.1s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }

.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
[data-theme="dark"] .btn-accent { color: #0d0b07; }
.btn-accent:hover { filter: brightness(0.95); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--ink-4); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface); color: var(--ink); }

.btn-ink {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
[data-theme="dark"] .btn-ink { color: #0d0b07; }

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

.btn-sm { padding: 5px 10px; font-size: 11.5px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }

/* ============================================================
   FORM FIELDS
   ============================================================ */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--ink-2);
}
.field-label .req { color: var(--rust); font-weight: 700; }

.field-label-hint {
  font-size: 10.5px;
  color: var(--ink-3);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

.field-input, .field-select, .field-textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  background: var(--bg);
  border-color: var(--accent);
}

.field-textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.55;
  padding: 12px;
}

.field-select { cursor: pointer; }

.field-input-mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

.field-hint {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 4px;
  line-height: 1.45;
}
.field-hint b { color: var(--ink-2); font-weight: 700; }

.field-with-prefix { position: relative; }
.field-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 13.5px;
  font-weight: 700;
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
}
.field-with-prefix .field-input { padding-left: 30px; }

.field-suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 700;
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
}

/* Toggles */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  transition: 0.2s;
  border-radius: 20px;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  transition: 0.2s;
  border-radius: 50%;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ============================================================
   FILTER PILLS
   ============================================================ */
.filter-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.filter-pill {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.filter-pill:hover { background: var(--surface-2); }
.filter-pill.active {
  background: var(--accent-2);
  color: var(--accent);
  font-weight: 700;
  border-color: var(--accent);
}
.filter-pill b {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
}

/* ============================================================
   COMMON CARDS
   ============================================================ */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card-soft {
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 18px;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-card-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
  color: #fff;
}
.stat-card-body { flex: 1; min-width: 0; }
.stat-card-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}
.stat-card-label {
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 3px;
}

/* Tip/info card */
.tip-card {
  background: linear-gradient(135deg, rgba(218,172,88,0.10) 0%, var(--bg) 60%);
  border: 1px solid var(--amber);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.tip-card.accent {
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--bg) 70%);
  border-color: var(--accent);
}
.tip-card-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.4;
}
.tip-card-body {
  flex: 1;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.55;
}
.tip-card-body b {
  color: var(--ink);
  font-weight: 700;
  display: block;
  margin-bottom: 3px;
}

/* Info bar (inline notice) */
.info-bar {
  background: var(--accent-2);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.info-bar b { color: var(--accent); font-weight: 700; }
.info-bar a { color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

.info-bar.warn {
  background: rgba(218,172,88,0.10);
  border-color: var(--amber);
}
.info-bar.warn b { color: var(--amber); }

.info-bar.rust {
  background: rgba(217,119,87,0.08);
  border-color: var(--rust);
}

/* Callout (sidebar style) */
.callout {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 13.5px;
  color: var(--ink-2);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  line-height: 1.65;
}
.callout.warn { border-left-color: var(--amber); background: rgba(218,172,88,0.08); }
.callout.info { border-left-color: var(--blue); background: rgba(41,128,185,0.06); }
.callout-icon { font-size: 17px; flex-shrink: 0; line-height: 1.4; }
.callout b { color: var(--ink); font-weight: 700; display: block; margin-bottom: 3px; }

/* ============================================================
   DEAL DISCOUNT RIBBON (shared by deals feed + new deal preview)
   ============================================================ */
.discount-ribbon {
  padding: 4px 10px;
  background: linear-gradient(135deg, var(--rust), #a34e2e);
  color: #fff;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: inline-block;
}
.discount-ribbon.boosted {
  background: linear-gradient(135deg, #f97316, #c2410c);
}
.discount-ribbon.expired {
  background: linear-gradient(135deg, var(--ink-3), var(--ink-4));
}

/* ============================================================
   STATUS PILLS (used everywhere)
   ============================================================ */
.status-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status-pill.ok    { background: rgba(39,174,96,0.12); color: var(--green); }
.status-pill.active{ background: var(--accent-2); color: var(--accent); }
.status-pill.pending{ background: rgba(218,172,88,0.15); color: #b88a2e; }
[data-theme="dark"] .status-pill.pending { color: var(--amber); }
.status-pill.expired{ background: var(--surface); color: var(--ink-3); }
.status-pill.warn  { background: rgba(218,172,88,0.15); color: #b88a2e; }
.status-pill.error { background: rgba(217,119,87,0.15); color: var(--rust); }

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.status-dot.green { background: var(--green); }
.status-dot.amber { background: var(--amber); }
.status-dot.rust  { background: var(--rust); }
.status-dot.gray  { background: var(--ink-3); }
.status-dot.pulse {
  animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-3);
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.breadcrumb a { cursor: pointer; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb span.sep { color: var(--ink-4); }

/* ============================================================
   PAGE HEAD (standard pattern)
   ============================================================ */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.ph-left {
  display: flex;
  gap: 14px;
  align-items: center;
}
.ph-icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
  background: var(--accent-2);
  color: var(--accent);
}
.ph-icon.amber  { background: rgba(218,172,88,0.12); color: #b88a2e; }
.ph-icon.rust   { background: rgba(217,119,87,0.12); color: var(--rust); }
.ph-icon.violet { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.ph-icon.blue   { background: rgba(41,128,185,0.12); color: var(--blue); }
.ph-icon.green  { background: rgba(39,174,96,0.12); color: var(--green); }
.ph-icon.orange { background: rgba(249,115,22,0.12); color: #ea580c; }

.ph-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ph-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 2px;
}
.ph-actions {
  display: flex;
  gap: 6px;
}

/* ============================================================
   RESPONSIVE: SHELL (layout + sidebar + topbar)
   Page-specific responsive rules live in pages.css
   ============================================================ */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .left-sidebar { display: none; }
  .tb-nav { display: none; }
}
@media (max-width: 560px) {
  .page { padding: 14px; }
  .tb-search { display: none; }
  .tb-icon-btn:not(:last-of-type) { display: none; }
  .field-grid-2, .field-grid-3 { grid-template-columns: 1fr; }
}
