/* =============================================================================
   AppHub — base.css
   Universal design tokens + cross-page primitives. Linked from every page on
   apps.publicstorage.ai. Page-specific styles live in each page's <style>
   block; this file is the single source of truth for the shared bones.
   ============================================================================= */

/* Font Awesome 7 Pro is loaded via the kit script in each page's <head>:
   <script src="https://kit.fontawesome.com/b8ed46ba7b.js" crossorigin="anonymous"></script>
   The kit serves only the icons referenced on the page and includes all
   weights (fa-light/regular/solid/thin/duotone). */

/* ─── Design tokens ──────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --ps-orange:    #E85D26;
  --ps-orange-dk: #C44D1C;
  --ps-orange-lt: #FFF0EA;

  /* Neutrals */
  --ink:    #111318;
  --ink-2:  #3D4047;
  --ink-3:  #797D88;
  --rule:   #E8E9EC;
  --surface:#F5F6F8;
  --white:  #FFFFFF;

  /* Brand secondary — used in dark hero strips on app-detail, leaderboard, etc. */
  --ps-navy: #0F274D;

  /* Semantic */
  --green:    #16a34a;  --green-lt: #dcfce7;
  --red:      #dc2626;  --red-lt:   #fee2e2;
  --yellow:   #d97706;  --yellow-lt:#fef3c7;
  --blue:     #2563eb;  --blue-lt:  #dbeafe;
  --gray:     #6b7280;  --gray-lt:  #f3f4f6;
  /* status.html historically used --amber as an alias for --yellow */
  --amber:    #d97706;

  /* Radii + shadows — values match the dominant customer-facing pages.
     Admin/build use 10px radius via their own :root override. */
  --radius:    12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12);
}

/* ─── Reset + body baseline ─────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface);
  color: var(--ink);
  min-height: 100vh;
}

/* ─── Site chrome (header + logo + back/ghost links) ─────────────────────────
   Used on /, /leaderboard, /apps/{slug}, /groups/{id}, /status. Previously
   duplicated verbatim in each page's <style>. Pages that need a narrower
   header (e.g. /status) override .header-inner locally — everything else
   inherits the 1200px default. */
header {
  background: var(--white);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 64px;
}
.header-left    { display: flex; align-items: center; gap: 18px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-crumb {
  font-size: 13px; font-weight: 500; color: var(--ink-3);
  padding-left: 18px; border-left: 1px solid var(--rule);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-mark {
  width: 36px; height: 36px; background: var(--ps-orange);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: white;
}
.logo-text { font-size: 15px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.logo-sub  { font-size: 11px; font-weight: 400; color: var(--ink-3); letter-spacing: .03em; }

.back-link {
  font-size: 13px; color: var(--ink-3); text-decoration: none;
  display: flex; align-items: center; gap: 5px; transition: color .15s;
}
.back-link:hover { color: var(--ps-orange); }

.btn-ghost {
  padding: 8px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--ink-2);
  text-decoration: none; border: 1px solid var(--rule); background: transparent;
  cursor: pointer; transition: all .15s;
}
.btn-ghost:hover { background: var(--surface); color: var(--ink); }

/* ─── Loading skeleton ──────────────────────────────────────────────────────
   Shared shimmer placeholder used by index, leaderboard, app-detail, group-detail
   while the catalog or app data loads. Theme-token colors so it adapts if the
   palette ever shifts. */
.skeleton {
  background: linear-gradient(90deg, var(--rule) 25%, #efefef 50%, var(--rule) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Buttons — primary action ───────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: 8px;
  background: var(--ps-orange); color: white;
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s;
}
.btn-primary:hover { background: var(--ps-orange-dk); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--rule); border-radius: 7px;
  background: white; color: var(--ink-2);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-secondary:hover { border-color: var(--ps-orange); color: var(--ps-orange); }

.btn-sm {
  padding: 6px 14px; border-radius: 6px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s; text-decoration: none;
  border: 1px solid var(--rule); color: var(--ink-2); background: white;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-sm:hover { border-color: var(--ps-orange); color: var(--ps-orange); }

.btn-cancel {
  padding: 8px 16px; border-radius: 7px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 500;
  border: 1px solid var(--rule); background: white; color: var(--ink-2);
  transition: background .15s;
}
.btn-cancel:hover { background: var(--surface); }

.btn-confirm {
  padding: 9px 18px; border-radius: 7px; border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; color: white;
  transition: filter .15s;
}
.btn-confirm:hover { filter: brightness(.92); }
.btn-confirm.orange { background: var(--ps-orange); }
.btn-confirm.green  { background: var(--green); }
.btn-confirm.red    { background: var(--red); }
.btn-confirm.blue   { background: var(--blue); }

.btn-retire {
  padding: 9px 18px; border-radius: 8px; border: 1px solid #fca5a5;
  background: white; color: var(--red);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.btn-retire:hover { background: var(--red-lt); }

/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 1000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: 14px;
  padding: 26px 28px; width: 100%; max-width: 540px;
  max-height: calc(100vh - 40px); overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-title {
  font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 4px;
  overflow-wrap: break-word; word-break: break-word;
}
.modal-sub {
  font-size: 13px; color: var(--ink-3); margin-bottom: 20px;
  overflow-wrap: break-word;
}
.modal-section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3);
  margin: 20px 0 10px; padding-bottom: 4px; border-bottom: 1px solid var(--rule);
}
.modal-section-title:first-child { margin-top: 0; }
.modal-field { margin-bottom: 14px; }
.modal-label {
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 5px; display: block;
}
.modal-input, .modal-select, .modal-textarea {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--rule); border-radius: 8px;
  font-family: inherit; font-size: 14px; outline: none; box-sizing: border-box;
  background: white; color: var(--ink);
  transition: border-color .15s;
}
.modal-input:focus, .modal-select:focus, .modal-textarea:focus { border-color: var(--ps-orange); }
.modal-textarea { resize: vertical; min-height: 70px; font-family: inherit; }
.modal-hint    { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px;
  flex-wrap: wrap;
}
.req { color: var(--red); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.table-wrap > table { min-width: 760px; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 11px 16px; text-align: left;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); background: var(--surface);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
td {
  padding: 14px 16px; font-size: 13px;
  border-bottom: 1px solid var(--rule); vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td      { background: #fafafa; }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
}
.badge.pending  { background: var(--yellow-lt); color: var(--yellow); }
.badge.live     { background: var(--green-lt);  color: var(--green); }
.badge.rejected { background: var(--red-lt);    color: var(--red); }
.badge.retired  { background: var(--surface);   color: var(--ink-3); }
.badge.error    { background: var(--red-lt);    color: var(--red); }
.badge.approved { background: var(--blue-lt);   color: var(--blue); }

.vis-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 14px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.vis-badge.vis-public  { background: #dbeafe; color: #1e40af; }
.vis-badge.vis-group   { background: #ede9fe; color: #6d28d9; }
.vis-badge.vis-private { background: #f3f4f6; color: #4b5563; }

/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 12px 22px; border-radius: 10px;
  background: var(--ink); color: white;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 1100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast.error   { background: var(--red); }
.toast.success { background: var(--green); }

/* ─── Empty states / spinners ────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--ink-3);
}
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--ink-3); }
.no-versions, .version-loading {
  font-size: 13px; color: var(--ink-3); padding: 12px 0;
}

/* ─── Utility classes (inline-style sweep targets) ──────────────────────── */

/* File-list row pattern used in App Storage on My Apps + Admin. Light-orange
   row with name on the left, meta sub-line, action buttons on the right. */
.fa-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--ps-orange-lt); font-size: 13px; flex-wrap: wrap;
  border-bottom: 1px solid var(--rule);
}
.fa-row:last-child { border-bottom: none; }
.fa-row-body { flex: 1; min-width: 0; }
.fa-row-name {
  font-family: 'DM Mono', monospace; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.fa-row-meta {
  font-size: 11px; color: var(--ink-3); margin-top: 2px;
}
.fa-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Pill chip — filter chips, group labels, etc. */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--rule); border-radius: 14px;
  background: white; color: var(--ink-2);
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all .12s;
}
.chip:hover  { border-color: var(--ps-orange); color: var(--ps-orange); }
.chip.active { background: var(--ps-orange); border-color: var(--ps-orange); color: white; }

/* Inline code formatting */
code, .mono {
  font-family: 'DM Mono', monospace;
  font-size: .92em;
}

/* SR-only / hidden helpers */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .9s linear infinite; }

/* ─── SQLite Workbench (shared between /my-apps + /admin) ─────────────────
   Tabbed full-width layout. Result tables live inside .db-wb-scroll for
   horizontal scrolling without breaking the surrounding panel. */
.db-wb { background: white; border: 1px solid var(--rule); border-radius: 10px; padding: 14px; margin-top: 18px; }
.db-wb-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.db-wb-title { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); flex-wrap: wrap; min-width: 0; }
.db-wb-title select { font-size: 12px; padding: 5px 9px; border: 1px solid var(--rule); border-radius: 6px; font-family: 'DM Mono', monospace; background: white; max-width: 100%; }
.db-wb-fs-btn { padding: 5px 11px; border: 1px solid var(--rule); background: white; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); cursor: pointer; transition: background .12s; }
.db-wb-fs-btn:hover { background: var(--surface); color: var(--ink); }

.db-wb-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin-bottom: 14px; }
.db-wb-tab { padding: 8px 16px; border: none; background: none; border-bottom: 2px solid transparent; font-size: 13px; font-weight: 600; color: var(--ink-3); cursor: pointer; transition: color .12s, border-color .12s; margin-bottom: -1px; }
.db-wb-tab:hover { color: var(--ink); }
.db-wb-tab.active { color: var(--ps-orange); border-bottom-color: var(--ps-orange); }

.db-wb-table-picker { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.db-wb-table-picker label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.db-wb-table-picker select { font-size: 13px; padding: 7px 32px 7px 12px; border: 1px solid var(--rule); border-radius: 6px; font-family: 'DM Mono', monospace; background: white; color: var(--ink); min-width: 240px; max-width: 100%; cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2210%22%20height%3D%226%22%20viewBox%3D%220%200%2010%206%22%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22%23797D88%22%20stroke-width%3D%221.5%22%20d%3D%22M1%201l4%204%204-4%22/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.db-wb-table-picker select:focus { outline: none; border-color: var(--ps-orange); }
.db-wb-table-count { font-size: 11px; color: var(--ink-3); font-family: 'DM Mono', monospace; }

.db-wb-empty { font-size: 13px; color: var(--ink-3); padding: 8px 2px; }
.db-wb-table-view { font-size: 12px; }
.db-wb-schema { margin-bottom: 10px; padding: 10px 12px; background: var(--surface); border-radius: 6px; font-family: 'DM Mono', monospace; font-size: 11px; color: var(--ink-2); line-height: 1.7; overflow-wrap: break-word; }
.db-wb-schema strong { color: var(--ink); }

.db-wb-scroll { border: 1px solid var(--rule); border-radius: 7px; overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: 420px; overflow-y: auto; }
.db-wb-data-table { width: 100%; border-collapse: collapse; min-width: max-content; }
.db-wb-data-table th { position: sticky; top: 0; background: var(--surface); text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule); font-size: 11px; font-weight: 600; color: var(--ink-3); white-space: nowrap; z-index: 1; }
.db-wb-data-table td { padding: 6px 10px; border-bottom: 1px solid var(--rule); font-family: 'DM Mono', monospace; font-size: 11px; color: var(--ink); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-wb-data-table tr:last-child td { border-bottom: none; }

.db-wb-pager { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; gap: 8px; }
.db-wb-pager button { padding: 4px 10px; font-size: 11px; border: 1px solid var(--rule); background: white; border-radius: 5px; cursor: pointer; color: var(--ink-2); }
.db-wb-pager button:disabled { cursor: not-allowed; opacity: .45; }

.db-wb-sql { width: 100%; padding: 11px; border: 1.5px solid var(--rule); border-radius: 7px; font-family: 'DM Mono', monospace; font-size: 12px; resize: vertical; outline: none; box-sizing: border-box; line-height: 1.5; background: #fafbfc; color: var(--ink); }
.db-wb-sql:focus { border-color: var(--ps-orange); background: white; }
.db-wb-query-bar { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.db-wb-run-btn { padding: 8px 18px; background: var(--ps-orange); color: white; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s; }
.db-wb-run-btn:hover { background: var(--ps-orange-dk); }
.db-wb-export-btn { padding: 8px 14px; background: white; color: var(--ink-2); border: 1px solid var(--rule); border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; transition: border-color .12s, color .12s; }
.db-wb-export-btn:hover { border-color: var(--ps-orange); color: var(--ps-orange); }
.db-wb-export-btn:disabled { opacity: .45; cursor: not-allowed; }
.db-wb-hint { font-size: 11px; color: var(--ink-3); }
.db-wb-result { margin-top: 12px; }
.db-wb-result-meta { font-size: 11px; color: var(--ink-3); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.db-wb-error { color: var(--red); font-family: 'DM Mono', monospace; font-size: 11px; padding: 10px 12px; background: #fee2e2; border-radius: 6px; border: 1px solid #fca5a5; }

body.db-wb-fullscreen { overflow: hidden; }
.db-wb.fullscreen { position: fixed; inset: 0; z-index: 200; border-radius: 0; border: none; margin: 0; padding: 24px 28px; overflow-y: auto; background: white; display: flex !important; flex-direction: column; }
.db-wb.fullscreen .db-wb-scroll { max-height: calc(100vh - 320px); }

/* ─── Responsive guards ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .modal { padding: 22px 20px; }
}
