/* =============================================================================
   Poibil - Meet Platform
   Corporate UI stylesheet. Vanilla CSS3, no framework, light and dark aware.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-sunken: #f0f2f5;
  --surface-hover: #eceff3;

  /* Lines and text */
  --border: #d8dde5;
  --border-strong: #c2cad6;
  --text: #16202c;
  --text-secondary: #4a5666;
  --text-muted: #6b7787;

  /* Brand and semantics */
  --accent: #0b4f9e;
  --accent-hover: #093f80;
  --accent-subtle: #e8f0f9;
  --danger: #b4232c;
  --danger-hover: #96181f;
  --danger-subtle: #fbeaeb;
  --record: #c0392b;
  --record-hover: #a03024;
  --success: #1c7a4a;

  /* Metrics */
  --radius: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-sunken: #1c2230;
    --surface-hover: #222a37;

    --border: #262d38;
    --border-strong: #333c4a;
    --text: #e6edf3;
    --text-secondary: #b3bdc9;
    --text-muted: #8b94a3;

    --accent: #3d8bfd;
    --accent-hover: #5c9dff;
    --accent-subtle: #14243c;
    --danger: #e5534b;
    --danger-hover: #f0655d;
    --danger-subtle: #2c1618;
    --record: #e5534b;
    --record-hover: #f0655d;
    --success: #3fb950;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over any display rule set further down
   (#callView uses flex, .button uses inline-flex), so it is enforced here. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.011em; color: var(--text); }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }

/* Icon sprite host is never rendered. */
.icon-sprite { display: none; }

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-inline { width: 14px; height: 14px; }

/* -------------------------------------------------------------------- main */
/* Left aligned: this is a demo/reference page, not a marketing layout. */
.app-main {
  flex: 1;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
}

/* Panels stretch by default; the join form keeps a readable measure. */
.app-main > * { width: 100%; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.panel-description {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.panel-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.panel-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --------------------------------------------------------------- join form */
.join-panel { max-width: 620px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

label, legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.005em;
}

.field-hint { font-size: 11.5px; color: var(--text-muted); }

input[type="text"], input[type="search"], select {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 11px;
  width: 100%;
  min-width: 0;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input::placeholder { color: var(--text-muted); }

input:focus-visible, select:focus-visible, button:focus-visible, a.button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.field-set {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.field-set legend { padding: 0 6px; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.checkbox input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

/* ----------------------------------------------------------------- buttons */
.button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.button:disabled { opacity: 0.5; cursor: not-allowed; }

.button-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.button-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.button-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.button-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.button-danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }

.button-record { background: var(--surface); color: var(--record); border-color: var(--border-strong); }
.button-record:hover:not(:disabled) { background: var(--danger-subtle); border-color: var(--record); }

.button-record-active { background: var(--record); color: #fff; border-color: var(--record); }
.button-record-active:hover:not(:disabled) { background: var(--record-hover); }

.button-control { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.button-control:hover:not(:disabled) { background: var(--surface-hover); }

/* Mic and camera: a disabled track is an exception state, so it reads red. */
.button-toggle[aria-pressed="false"] { background: var(--danger); color: #fff; border-color: var(--danger); }
.button-toggle[aria-pressed="false"]:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }

/* Screen share: not sharing is the normal state, so only sharing is marked. */
.button-control[aria-pressed="true"]:not(.button-toggle) {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.button-icon { padding: 6px; background: transparent; color: var(--text-secondary); border-color: transparent; }
.button-icon:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.button-small { padding: 5px 9px; font-size: 12px; gap: 5px; }
.button-small .icon { width: 14px; height: 14px; }

/* -------------------------------------------------------------- call panel */
#callView { display: flex; flex-direction: column; gap: 16px; }

.call-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
}

.call-identity { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.call-room {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}

.call-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.call-meta .status-pill { margin-left: 4px; }

/* Status pills live in the call bar: connection state and recording state. */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-sunken);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
  flex-shrink: 0;
}

.status-idle { color: var(--text-muted); }

.status-connected {
  color: var(--success);
  border-color: var(--success);
  background: transparent;
}

.status-connected .status-dot { opacity: 1; }

.status-connecting {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

.status-error {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.status-recording {
  color: #fff;
  background: var(--record);
  border-color: var(--record);
}

.status-recording .status-dot { opacity: 1; animation: blink 1.6s ease-in-out infinite; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

@media (prefers-reduced-motion: reduce) {
  .status-recording .status-dot { animation: none; }
}

.call-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.control-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 2px;
}

/* --------------------------------------------------------------- video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

/* A lone participant should not be stretched across the full viewport. */
.video-grid:has(> .video-tile:only-child) { max-width: 880px; }

/* Two tiles read better side by side than as one very wide row. */
.video-grid:has(> .video-tile:nth-child(2):last-child) { max-width: 1100px; }

.video-tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-tile.is-local video { transform: scaleX(-1); }
.video-tile.is-screen video { object-fit: contain; }
.video-tile.is-screen.is-local video { transform: none; }

.video-tile.speaking {
  border-color: var(--success);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 45%, transparent);
}

.tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #11161f;
}

.tile-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #2a3444;
  color: #cbd5e1;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tile-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 4px 9px;
  border-radius: 4px;
  background: rgba(10, 14, 20, 0.78);
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ tables */
.table-container { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 760px;
}

.data-table th {
  text-align: left;
  padding: 9px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-sunken); }

.data-table .numeric { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions-column { text-align: right; }

.cell-room { color: var(--text); font-weight: 500; }

.cell-file {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  max-width: 300px;
  overflow-wrap: anywhere;
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.table-message td {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
}

/* ------------------------------------------------------------------ alerts */
.alert {
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 12.5px;
  border: 1px solid transparent;
}

.alert-error {
  color: var(--danger);
  background: var(--danger-subtle);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

/* ------------------------------------------------------------------ dialog */
.player-dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  width: min(900px, 92vw);
  box-shadow: var(--shadow-md);
}

.player-dialog::backdrop { background: rgba(9, 13, 20, 0.6); }

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

#playerTitle {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.player-dialog video {
  display: block;
  width: 100%;
  max-height: 68vh;
  background: #000;
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 720px) {
  .app-main { padding: 16px; gap: 16px; }
  .call-bar { align-items: stretch; }
  .call-controls { width: 100%; }
  .call-controls .button { flex: 1 1 auto; }
  .control-divider { display: none; }
  .panel-tools { width: 100%; }
  .panel-tools input { flex: 1; }
}

@media (max-width: 520px) {
  .call-controls .button-label { display: none; }
  .call-controls .button { padding: 9px; }
  .call-controls #leaveBtn .button-label { display: inline; }
}
