/*
 * 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 { background: var(--accent); filter: brightness(1.08); }
.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; }

/* --- bridge: settings toggles --- */
.switch-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row:last-child { border-bottom: none; }
.switch-row input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--accent); }

/* --- bridge: online table --- */
.bt { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1000px) { .bt { grid-template-columns: minmax(0, 1fr) 300px; } .gpx-container:has(.bt) { max-width: 1240px; } }
.bt__info { font-size: 0.85rem; margin-bottom: 8px; }
.bt__controls { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.felt {
  display: grid; gap: 8px; padding: 12px; border-radius: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-areas: ". top ." "left center right" "bottom bottom bottom";
  background: radial-gradient(ellipse at center, #2b7a55 0%, #1d5c3f 70%, #174a33 100%);
  color: #f2f7f4; min-height: 420px;
}
.seat { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; min-width: 0; }
.seat--top { grid-area: top; } .seat--left { grid-area: left; } .seat--right { grid-area: right; } .seat--bottom { grid-area: bottom; }
.seat__head { font-size: 0.85rem; padding: 3px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.25); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.seat__head--vul { box-shadow: inset 0 0 0 2px #e05a4f; }
.seat__tag { background: #f2f7f4; color: #174a33; border-radius: 6px; padding: 0 5px; font-size: 0.7rem; font-weight: 700; }
.seat--turn .seat__head { background: #f5c542; color: #1b2733; }
.seat__name em { opacity: 0.8; }
.felt__center { grid-area: center; display: grid; place-items: center; min-height: 170px; }
.center-msg { text-align: center; background: rgba(0, 0, 0, 0.2); padding: 12px 16px; border-radius: 12px; }
.center-msg .muted { color: #cfe3d8; }
.center-msg.result { display: grid; gap: 8px; }
.hand { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; max-width: 100%; }
.hand--hidden { gap: 0; }
.hand--hidden .pc--back + .pc--back { margin-left: -14px; }
.hand--mine { gap: 4px; }

/* Playing cards */
.pc { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 44px; height: 62px; border-radius: 6px; background: #fff; color: #1b2733; border: 1px solid #c9d3dc; font-weight: 700; line-height: 1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); font-family: system-ui, sans-serif; padding: 0; }
.pc__r { font-size: 1.05rem; } .pc__s { font-size: 1.2rem; }
.pc--red { color: #c0392b; }
.pc--sm { width: 30px; height: 42px; border-radius: 4px; }
.pc--sm .pc__r { font-size: 0.8rem; } .pc--sm .pc__s { font-size: 0.85rem; }
.pc--back { background: repeating-linear-gradient(45deg, #2f4f8f, #2f4f8f 4px, #3d63ad 4px, #3d63ad 8px); border-color: #e9eef5; }
.pc--play { cursor: pointer; outline: 2px solid #f5c542; transform: translateY(-6px); transition: transform 0.1s; }
.pc--play:hover { transform: translateY(-10px); }
.red { color: #c0392b; }

/* Trick in the middle */
.trick { position: relative; display: grid; gap: 4px; grid-template-columns: 50px 50px 50px; grid-template-rows: auto 64px 64px 64px;
  grid-template-areas: "title title title" ". top ." "left . right" ". bottom ."; align-items: center; justify-items: center; }
.trick__title { grid-area: title; font-size: 0.8rem; text-align: center; }
.trick__slot--top { grid-area: top; } .trick__slot--left { grid-area: left; } .trick__slot--right { grid-area: right; } .trick__slot--bottom { grid-area: bottom; }

/* Bidding box, auction, score */
.bbox { display: grid; gap: 4px; max-width: 360px; margin: 0 auto; padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.bbox__row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.bbox__row--special { grid-template-columns: 2fr 1fr 1fr; margin-top: 4px; }
.bbox__bid { padding: 6px 0; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-elev); color: var(--text); font-weight: 700; cursor: pointer; }
.bbox__bid:hover:not(:disabled) { border-color: var(--accent); }
.bbox__bid:disabled { opacity: 0.25; cursor: default; }
.bbox__pass { background: #2f8f5b; color: #fff; border-color: #2f8f5b; }
.bbox__x { background: #c0392b; color: #fff; border-color: #c0392b; }
.bbox__xx { background: #2f5fa8; color: #fff; border-color: #2f5fa8; }
.bbox__x:disabled, .bbox__xx:disabled { background: var(--bg-elev); color: var(--text); border-color: var(--line); }
.auction th, .auction td { text-align: center; padding: 4px; }
.score td, .score th { padding: 5px 6px; font-size: 0.85rem; }
.score .num { text-align: right; }
.past { margin: 8px 0 0; padding-left: 18px; font-size: 0.85rem; color: var(--muted); }
.claim { margin-bottom: 10px; }

@media (max-width: 640px) {
  .felt { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "top top" "left right" "center center" "bottom bottom"; padding: 8px; }
  .pc { width: 38px; height: 54px; }
  .pc--sm { width: 26px; height: 36px; }
}
.felt .btn--primary, .felt .btn--primary:hover { background: #f5c542; color: #1b2733; border-color: #f5c542; font-weight: 600; }
.bt__me { font-size: 0.8rem; margin: -4px 0 8px; }
.trick__title { width: 250px; justify-self: center; line-height: 1.4; }
.turn-me { display: inline-block; background: #f5c542; color: #1b2733; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.trick { grid-template-columns: 54px 54px 54px; }

/* --- bridge: table chat --- */
.tchat { display: flex; flex-direction: column; }
.tchat__log { max-height: 280px; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.tchat__msg { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 5px 9px; align-self: flex-start; max-width: 92%; }
.tchat__msg--mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 12%, var(--bg-elev)); }
.tchat__meta { font-size: 0.72rem; color: var(--muted); }
.tchat__text { font-size: 0.9rem; overflow-wrap: anywhere; }
.tchat__form { display: flex; gap: 6px; }
.tchat__form input { padding: 7px 10px; }

/* --- bridge: rubber score sheet --- */
.sheet__status { font-size: 0.85rem; margin-bottom: 8px; }
.sheet { width: 100%; }
.sheet td, .sheet th { padding: 4px 6px; font-size: 0.85rem; }
.sheet .num { text-align: right; width: 64px; }
.sheet__what { color: var(--muted); font-size: 0.78rem !important; }
.sheet__below tr:first-child td { border-top: 3px solid var(--text); }
.sheet__game td { padding: 0; border-bottom: 2px dashed var(--muted); height: 4px; }

/* --- bridge: practice table bar --- */
.practice-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 12px; margin-bottom: 8px; border: 1px dashed var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 6%, var(--bg-elev)); font-size: 0.9rem; }
.practice-bar__group { display: inline-flex; gap: 4px; align-items: center; }
.practice-bar input[type="checkbox"] { width: auto; }
