/*
 * Kjelsås Bridge — frontend framework, from Generisk frontend-core/css/style.css
 * (rehearsal-player styles removed, chat/list styles added at the bottom).
 * Dark/light via CSS custom properties. The brand accent (--accent) and any other
 * tokens are set at runtime from the instance config by frontend-core/js/config.js
 * (which writes them as inline styles on :root, so they win in both light and dark).
 * Chrome/layout classes use the `gpx-` prefix (matching navigation.js); generic
 * utilities (card, btn, form, modal, …) are unprefixed.
 */

:root {
  --bg: #f5f7f9;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #5f7180;
  --line: #dde5ec;
  --accent: #2f7d6b;        /* overridden by config theme.colors['--accent'] */
  --accent-text: #ffffff;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(16, 34, 48, 0.08), 0 1px 2px rgba(16, 34, 48, 0.06);
  --radius: 12px;
}

:root[data-theme='dark'] {
  --bg: #10171e;
  --bg-elev: #172029;
  --card: #172029;
  --text: #e7edf2;
  --muted: #9aa8b4;
  --line: #26323d;
  --accent-text: #06120f;
  --danger: #e57368;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: var(--accent); }

/* --- Topbar --- */
.gpx-topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--bg-elev); border-bottom: 1px solid var(--line);
}
.gpx-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--accent); text-decoration: none; }
.gpx-logo { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-size: 1rem; }
.gpx-topActions { display: flex; gap: 8px; }
.gpx-btnTheme, .gpx-btnIcon {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; width: 42px; height: 42px; font-size: 1.1rem; cursor: pointer;
}
.gpx-btnTheme:hover, .gpx-btnIcon:hover { background: var(--bg); }

/* --- Menu --- */
.gpx-menuOverlay { position: fixed; inset: 0; z-index: 50; background: rgba(9, 16, 22, 0.45); display: none; }
.gpx-menuOverlay.open { display: block; }
.gpx-menuPanel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(320px, 84vw);
  background: var(--bg-elev); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; animation: gpx-slide 0.18s ease;
}
@keyframes gpx-slide { from { transform: translateX(20px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.gpx-menuHeader { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.gpx-menuHeader h3 { margin: 0; font-size: 1rem; }
.gpx-closeBtn { background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.gpx-menuList { padding: 8px; overflow-y: auto; }
.gpx-menuItem { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: 0.98rem; }
.gpx-menuItem:hover { background: var(--bg); }
.gpx-menuItem--active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 600; }
.gpx-menuItem__icon { width: 24px; text-align: center; }

/* --- Layout --- */
.gpx-main { padding: 20px 16px 60px; }
.gpx-container { max-width: 900px; margin: 0 auto; }
.gpx-pageHeader { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.gpx-pageHeader h1 { margin: 0; font-size: 1.5rem; }

/* --- Cards --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card__title { margin: 0 0 4px; font-size: 1.1rem; }
.card__meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.card--pinned { border-color: var(--accent); }
.grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .grid--2 { grid-template-columns: 1fr 1fr; } }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg-elev); color: var(--text); padding: 9px 14px; border-radius: 10px; font-size: 0.95rem; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn--primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn--primary:hover { filter: brightness(1.05); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn--sm { padding: 5px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- Forms --- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.9rem; margin-bottom: 5px; color: var(--muted); }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > * { flex: 1; min-width: 140px; }

/* --- Modal --- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(9, 16, 22, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__content { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.modal__header, .modal__footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; }
.modal__header { border-bottom: 1px solid var(--line); }
.modal__footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal__header h3 { margin: 0; font-size: 1.05rem; }
.modal__body { padding: 16px; }

/* --- Misc --- */
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty__icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.pill { display: inline-block; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.75rem; color: var(--muted); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 8px; }
.msg { padding: 10px 12px; border-radius: 10px; margin-top: 10px; font-size: 0.9rem; }
.msg--error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.msg--ok { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* --- Table --- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }

/* --- Loader --- */
.loader { position: fixed; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 70; }
.loader[hidden] { display: none; }
.loader__spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: gpx-spin 0.8s linear infinite; }
@keyframes gpx-spin { to { transform: rotate(360deg); } }

/* --- Comments --- */
.comment-list { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: none; }
.comment__meta { font-size: 0.8rem; color: var(--muted); }

/* --- Markdown --- */
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { line-height: 1.25; margin: 0.6em 0 0.3em; }
.md-body p { margin: 0.5em 0; }
.md-body ul { padding-left: 1.3em; margin: 0.5em 0; }
.md-body blockquote { border-left: 3px solid var(--accent); margin: 0.6em 0; padding: 0.2em 0.9em; color: var(--muted); }
.md-body pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
.md-body code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
.md-body pre code { background: none; padding: 0; }
.md-img, .md-body img { max-width: 100%; border-radius: 10px; margin: 6px 0; }

/* --- Markdown editor --- */
.md-toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.md-toolbar__btn { border: 1px solid var(--line); background: var(--bg-elev); color: var(--text); border-radius: 8px; min-width: 34px; height: 34px; cursor: pointer; font-weight: 600; }
.md-toolbar__btn:hover { background: var(--bg); }

/* --- Update banner --- */
#sw-update-banner { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; gap: 12px; align-items: center; background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 10px 14px; border-radius: 12px; }
#sw-update-banner button { border: none; background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 6px 12px; cursor: pointer; }

/* --- Login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: min(420px, 100%); }
.login-card h1 { margin: 0 0 4px; color: var(--accent); }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); }
.login-logo { font-size: 2rem; }

/* --- bridge: lists --- */
.plain-list { list-style: none; margin: 8px 0 12px; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: none; }
.card--past { opacity: 0.7; }

/* --- bridge: chat --- */
.chat { display: flex; flex-direction: column; padding: 0; height: calc(100vh - 190px); min-height: 360px; }
.chat__log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat__day { align-self: center; font-size: 0.75rem; color: var(--muted); margin: 8px 0 2px; }
.chat__more { align-self: center; }
.chat__msg { align-self: flex-start; max-width: min(80%, 560px); background: var(--bg); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 7px 11px; }
.chat__msg--mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--bg-elev)); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: 14px 14px 4px 14px; }
.chat__meta { font-size: 0.75rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chat__text { overflow-wrap: anywhere; }
.chat__del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.75rem; padding: 0 2px; margin-left: auto; }
.chat__del:hover { color: var(--danger); }
.chat__form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat__form textarea { min-height: 44px; max-height: 160px; resize: vertical; }
