/* EPerf standard UI: dark surface, #222 header bar, blue gradient accents, Segoe UI.
   Same house style as the eperflabs.com Apps Dashboard and fin2. */
:root {
  --bg: #111;
  --card: #1c1c1c;
  --head: #222;
  --text: #fff;
  --muted: #9a9a9a;
  --line: #333;
  --line-2: #444;
  --field: #141414;
  --brand: #0d6efd;
  --brand-2: #003cba;
  --brand-hi: #2a7eff;
  --out: #0d6efd;
  --in: #2a2a2a;
  --danger: #e66767;
  --ok: #3fb950;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  /* side gutters: never closer than 20px to the screen edge, and clear of the iPhone's rounded corners / landscape notch */
  --gl: max(20px, env(safe-area-inset-left, 0px));
  --gr: max(20px, env(safe-area-inset-right, 0px));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.45 "Segoe UI", Calibri, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
a { color: var(--brand-hi); text-decoration: none; }
.hidden { display: none !important; }
button, a.button {
  font: inherit; font-weight: 600; border: 1px solid var(--line-2); background: var(--field); color: var(--text);
  padding: 10px 16px; border-radius: 8px; cursor: pointer;
}
button:hover, a.button:hover { background: #1e1e1e; }
a.button { display: inline-block; text-align: center; text-decoration: none; }
button.primary, a.button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover, a.button.primary:hover { background: var(--brand-hi); }
button.danger { color: var(--danger); background: transparent; }
button.wide { width: 100%; margin-top: 12px; }
input, textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming into fields */
  padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--field); color: var(--text);
}
input, textarea { width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-hi); }
::placeholder { color: #777; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 22px; letter-spacing: .3px; }
h3 { font-size: 16px; margin-bottom: 10px; letter-spacing: .3px; }

.screen { height: 100%; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 14px 0; box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input, .row select { flex: 1 1 120px; min-width: 0; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0; }
.note { color: var(--muted); margin: 0; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

/* login */
#login { display: grid; place-items: center; padding: 20px var(--gr) 20px var(--gl); }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 24px 20px; }
.login-card label { text-align: left; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 14px; }

/* layout */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-t)) var(--gr) 12px var(--gl); background: var(--head); color: #fff;
  border-bottom: 2px solid var(--line-2);
}
.brandmark { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brandmark img { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
.brandmark > div { min-width: 0; }
.me-name { font-weight: 700; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-number { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #e3b341; box-shadow: 0 0 0 3px rgba(255,255,255,.12); flex-shrink: 0; }
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--danger); }
#views { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; -webkit-overflow-scrolling: touch; }
.view { display: none; min-height: 100%; padding: 0 var(--gr) 24px var(--gl); }
.view.active { display: block; }
.view[data-view="thread"].active { display: flex; flex-direction: column; height: 100%; padding: 0; }
.view-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 0 8px; gap: 8px; }
.icon-btn { border: none; background: transparent; font-size: 22px; padding: 6px 10px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list.compact li { padding: 10px 0; cursor: default; flex-wrap: wrap; }
.list li .grow { flex: 1; min-width: 0; }
.list li .title { font-weight: 600; }
.list li .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .meta { color: var(--muted); font-size: 13px; text-align: right; }
.list li.unread .title::after { content: ""; display: inline-block; width: 8px; height: 8px; background: var(--brand-hi); border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(145deg, var(--brand), var(--brand-2)); display: grid; place-items: center;
  font-weight: 700; color: #fff; flex-shrink: 0;
}
.missed .title, tr.missed td:first-child { color: var(--danger); }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--in); color: var(--muted); }
.list.compact button, .list.compact select { padding: 6px 10px; font-size: 14px; }
select { padding: 8px; }

/* thread */
.thread-head { padding: 8px var(--gr) 8px calc(var(--gl) - 10px); border-bottom: 1px solid var(--line); background: var(--head); }
.thread-to { border: none; background: transparent; font-weight: 600; padding: 6px; }
.bubbles { flex: 1; overflow-y: auto; padding: 12px var(--gr) 4px var(--gl); display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: var(--in); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.out { background: var(--out); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; }
.stamp { font-size: 11px; color: var(--muted); align-self: center; margin: 8px 0 2px; }
.bubble-status { font-size: 11px; color: var(--muted); align-self: flex-end; margin-top: -2px; }
.bubble-status.failed { color: var(--danger); }
.composer { display: flex; gap: 8px; padding: 8px var(--gr) calc(8px + var(--safe-b)) var(--gl); border-top: 1px solid var(--line); background: var(--head); }
.composer textarea { resize: none; max-height: 120px; border-radius: 20px; }
.send { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex-shrink: 0; align-self: flex-end; }

.from-row { display: flex; align-items: center; gap: 8px; padding: 6px var(--gr) 6px var(--gl); font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); background: var(--head); }
.from-row.center { justify-content: center; border: none; background: transparent; padding-top: 18px; }
.from-row select { flex: 0 1 auto; }
.notice { background: #3a3014; color: #f3dc9b; border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.notice ul { margin: 6px 0 0 18px; padding: 0; }
.line-tag { font-size: 12px; color: var(--muted); }
.flag { font-size: 18px; }

/* keypad */
.dial-display { display: flex; align-items: center; padding: 24px 0 8px; }
.dial-display input { border: none; background: transparent; font-size: 30px; text-align: center; letter-spacing: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 300px; margin: 10px auto; }
.keypad button {
  aspect-ratio: 1; border-radius: 50%; font-size: 28px; font-weight: 400; display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1; border: 1px solid var(--line); background: var(--card);
  padding: 0; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.keypad button small { font-size: 10px; letter-spacing: 2px; color: var(--muted); margin-top: 3px; }
.keypad.small { max-width: 240px; gap: 10px; }
.keypad.small button { font-size: 22px; background: rgba(255,255,255,.12); color: #fff; box-shadow: none; border: none; }
.keypad.small button small { color: rgba(255,255,255,.6); }
.call-btn {
  display: block; margin: 16px auto; width: 72px; height: 72px; border-radius: 50%; border: none;
  background: var(--ok); color: #fff; font-size: 30px; padding: 0;
}

/* tabs */
.tabs { display: flex; border-top: 2px solid var(--line-2); background: var(--head); padding: 0 var(--gr) var(--safe-b) var(--gl); }
.tabs button {
  flex: 1; border: none; border-radius: 0; background: transparent; font-size: 11px; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; position: relative;
}
.tabs button span { font-size: 20px; }
.tabs button.active { color: var(--brand-hi); }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px); background: var(--danger); color: #fff;
  font-style: normal; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; line-height: 18px;
}

/* call overlay */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: linear-gradient(180deg, #0a2a6b, #07163a);
  color: #fff; display: flex; flex-direction: column; align-items: center;
  padding: calc(60px + var(--safe-t)) var(--gr) calc(40px + var(--safe-b)) var(--gl);
}
.call-who { font-size: 30px; font-weight: 600; text-align: center; }
.call-state { opacity: .8; margin-top: 6px; }
.call-timer { font-variant-numeric: tabular-nums; margin-top: 4px; opacity: .9; }
.incoming-actions, .active-actions { margin-top: auto; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.incoming-actions { flex-direction: row; justify-content: space-around; max-width: 320px; }
.row-actions { display: flex; gap: 22px; }
.round {
  width: 70px; height: 70px; border-radius: 50%; border: none; font-size: 26px; color: #fff; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.round small { font-size: 11px; margin-top: 2px; }
.round.accept { background: var(--ok); }
.round.decline { background: #d0342c; }
.round.ghost { background: rgba(255,255,255,.14); }
.round.ghost.on { background: #fff; color: #0a2a6b; }
.round.big { width: 76px; height: 76px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  background: #2a2a2a; border: 1px solid var(--line-2); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: calc(100% - 40px);
}

.app-footer { text-align: center; font-size: 13px; color: var(--muted); padding: 22px 0 8px; border-top: 1px solid var(--line); margin-top: 24px; }

/* password eye */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 44px; }
.pw-eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); background: none !important; border: 0; padding: 8px 12px; font-size: 18px; cursor: pointer; opacity: .5; }
.pw-eye.on { opacity: 1; }

/* EperfTable */
.et-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.et-bar .et-search { flex: 1 1 160px; min-width: 0; width: auto; }
.et-bar select { flex: 0 0 auto; }
.et-btn { padding: 8px 12px; font-size: 14px; }
.et-btn.et-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.et-count { margin: 12px 2px 4px; color: var(--muted); font-size: 13px; }
.et-count b { color: var(--text); }
.et-pager { display: flex; gap: 4px; align-items: center; justify-content: flex-end; flex-wrap: wrap; font-size: 13px; margin: 6px 0; }
.et-pg { border: none; background: transparent; color: var(--brand-hi); padding: 6px 8px; border-radius: 6px; font-weight: 400; }
.et-pg:hover { background: rgba(255,255,255,.06); }
.et-pg.off { color: #555; cursor: default; background: transparent; }
.et-cur { color: var(--muted); padding: 0 6px; }
.et-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 10px; background: var(--card); -webkit-overflow-scrolling: touch; }
.et-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.et-table th, .et-table td { padding: 8px 10px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); white-space: nowrap; }
.et-table thead th { position: sticky; top: 0; background: var(--card); z-index: 5; border-bottom: 1px solid var(--line-2); }
.et-table tbody tr[data-peer] { cursor: pointer; }
.et-table tbody tr:hover td { background: rgba(255,255,255,.03); }
.et-table td button, .et-table td select { padding: 5px 10px; font-size: 13px; }
.et-sort { border: none; background: transparent; padding: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: .3px; }
.et-lbl { font-weight: 700; }
.et-fbtn { display: flex; justify-content: space-between; align-items: center; gap: 6px; min-width: 64px; padding: 3px 8px; font-size: 12px; font-weight: 400; border-radius: 6px; }
.et-fbtn.active { border-color: var(--brand-hi); color: var(--brand-hi); }
.et-car { opacity: .65; font-size: 10px; }
.et-state { text-align: center; color: var(--muted); padding: 28px 10px !important; white-space: normal !important; }
.et-state.err { color: var(--danger); }
.et-panel {
  position: fixed; z-index: 70; background: #161b22; border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,.55); padding: 8px; font-size: 13px;
}
.et-panel .et-psearch { padding: 7px 8px; font-size: 16px; margin-bottom: 6px; background: #0e1116; }
.et-pall { display: flex; gap: 7px; align-items: center; color: var(--muted); padding: 4px 2px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.et-panel input[type=checkbox] { width: auto; }
.et-plist { max-height: 230px; overflow-y: auto; }
.et-plist label { display: flex; gap: 7px; align-items: center; padding: 5px 2px; cursor: pointer; white-space: nowrap; }
.et-plist label:hover { background: rgba(255,255,255,.05); }
.et-ptrunc { font-size: 11px; color: var(--muted); padding: 4px 2px; }
.et-pbar { display: flex; justify-content: space-between; gap: 6px; margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }

/* admin cost tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0 6px; }
.tile { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tile .k { color: var(--muted); font-size: 12px; letter-spacing: .3px; }
.tile .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.tile .v.bad { color: var(--danger); }
.tile .s { color: var(--muted); font-size: 12px; }

/* sign-in steps */
#login { overflow-y: auto; align-content: center; }
#login .login-card { margin: 14px auto; }
.link { background: none; border: none; color: var(--brand-hi); padding: 6px; font-weight: 400; text-align: center; text-decoration: none; }
.link:hover { background: none; text-decoration: underline; }
.code-input { text-align: center; font-size: 26px; letter-spacing: 6px; }
.steps { text-align: left; margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
.qr { background: #fff; border-radius: 12px; padding: 8px; width: 236px; height: 236px; margin: 0 auto; }
.qr svg { width: 220px; height: 220px; display: block; }
.keybox { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }
.keybox code { background: var(--field); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 8px; font-size: 14px; letter-spacing: 1px; word-break: break-all; }

/* terms: graphical panels */
#tos { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tos-wrap { max-width: 920px; margin: 0 auto; padding: calc(20px + var(--safe-t)) var(--gr) calc(28px + var(--safe-b)) var(--gl); }
.tos-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tos-lead { text-align: center; color: var(--muted); margin: 10px 0 14px; }
.tos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.tos-panel {
  display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.3); transition: border-color .2s, background .2s, transform .2s;
}
.tos-panel:hover { transform: translateY(-2px); border-color: var(--line-2); }
.tos-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 26px; background: linear-gradient(145deg, var(--brand), var(--brand-2)); }
.tos-panel h3 { margin: 4px 0 0; font-size: 17px; }
.tos-panel p { margin: 0; color: #cfcfcf; font-size: 14px; flex: 1; }
.tos-legal-h { margin: 26px 0 8px; font-size: 18px; }
.tos-legal { background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; padding: 14px 16px; max-height: 55vh; overflow-y: auto; font-size: 13.5px; color: #d6d6d6; line-height: 1.55; }
.tos-legal h4 { margin: 14px 0 4px; font-size: 14px; color: #fff; }
.tos-legal h4:first-child { margin-top: 0; }
.tos-legal p { margin: 0 0 6px; }
.tos-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tos-actions .primary { flex: 1 1 200px; padding: 13px 16px; font-size: 17px; }
.tos-actions .primary:disabled { opacity: .4; cursor: not-allowed; }

/* admin: status, review */
.pill.ok { background: #16351f; color: var(--ok); }
.pill.bad { background: #3a1a1a; color: var(--danger); }
.cell-msg { max-width: 360px; min-width: 180px; white-space: normal; }
tr.flagged td { background: rgba(230,103,103,.10); }
tr.revoked td { opacity: .65; }

.legal-line { text-align: center; margin: 4px 0 0; }
.legal-line a, .app-footer a { color: var(--brand-hi); }
