/* Phone Finder — full-window layout: top bar + comparison table that fits the screen. */
:root {
  font-family: 'DM Sans', sans-serif;
  color: #172033;
  background: #f7f8fc;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --border: #e5e9f1;
  --line: #e1e6ee;        /* light cell borders */
  --zebra: #f2f5fa;       /* every other row */
  --zebra-label: #e9eef6; /* label cell on a zebra row */
  --accent: #315ee8;
  --muted: #7c8799;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { overflow: hidden; background: #f7f8fc; }
button, textarea { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: #9ba4b4; font-weight: 400; }
.warn { color: #b7791f; }

/* ---- App shell -------------------------------------------------------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px clamp(8px, 1.5vw, 20px) clamp(8px, 1.5vw, 16px);
  gap: 8px;
}
.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}
.bar h1 { flex: 1; min-width: 0; font: 800 clamp(15px, 1.6vw, 20px) Manrope, sans-serif; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { flex: none; display: flex; align-items: center; gap: 8px; }

.button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.button.secondary { background: #fff; color: #34435e; border: 1px solid #dfe4ee; }
.button:disabled { opacity: .55; cursor: default; }
.button:focus-visible, .info-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.error {
  flex: none;
  padding: 9px 12px;
  border: 1px solid #f2caca;
  background: #fff5f5;
  color: #a33b3b;
  border-radius: 8px;
  font-size: 13px;
}

/* ---- "i" button + tooltip ------------------------------------------- */
.info-wrap { position: relative; }
.info-button {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #f3dfb6;
  background: #fffaf0;
  color: #8a5a00;
  font: 700 italic 16px Georgia, serif;
  cursor: pointer;
}
.info-count {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #d9480f;
  color: #fff;
  font: 700 10px/17px 'DM Sans', sans-serif;
}
.info-tip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(420px, calc(100vw - 24px));
  max-height: min(60vh, 480px);
  overflow: auto;
  background: #fffdf8;
  border: 1px solid #f3dfb6;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px #27345c26;
}
.info-wrap:hover .info-tip,
.info-wrap:focus-within .info-tip,
.info-wrap.open .info-tip { display: block; }
.info-tip h3 { font: 700 13px Manrope, sans-serif; color: #7a5410; margin: 0 0 8px; }
.info-tip ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.info-tip li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 12.5px; color: #4d5a70; overflow-wrap: anywhere; }
.info-tip .reason { flex-basis: 100%; color: var(--muted); }
.badge { font-size: 10px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; padding: 2px 7px; border-radius: 20px; background: #eef1f8; color: #566176; }
.badge-invalid, .badge-error { background: #fdeaea; color: #a33b3b; }
.badge-duplicate { background: #e9efff; color: var(--accent); }
.badge-not_found { background: #fff1d6; color: #8a5a00; }
.badge-not_phone { background: #f1e9ff; color: #6b3fc9; }

/* ---- Stage: loading / empty / table -------------------------------- */
.stage { flex: 1; min-height: 0; position: relative; }
.loading, .empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #53617a;
  font-size: 14px;
}
.loading { flex-direction: row; }
.empty p { margin: 0; color: var(--muted); }
.empty p:empty { display: none; }
.spinner { width: 19px; height: 19px; border: 2px solid #dce4ff; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The table fills the stage; script.js sets --fs (font size) so it fits without scrolling. */
.table-wrap {
  --fs: 14px;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: var(--fs);
}
.table-wrap.overflowing { overflow: auto; } /* fallback for very small screens */
.compare-table {
  width: 100%;
  height: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  line-height: 1.35;
}
.compare-table col.label-col { width: 7.5em; }
.compare-table th, .compare-table td {
  padding: .45em .7em;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
}
/* Last resort when even the smallest font does not fit: allow breaking inside words. */
.table-wrap.overflowing th, .table-wrap.overflowing td { overflow-wrap: anywhere; hyphens: auto; overflow: visible; }
.compare-table td { color: #1f2a3d; font-weight: 500; background: #fff; }
.compare-table tbody tr:nth-child(even) td { background: var(--zebra); }
.compare-table tbody tr:nth-child(even) th.spec-label { background: var(--zebra-label); }
.compare-table thead th { border-top: 0; border-bottom: 1px solid #d5dbe6; background: #f3f5fa; position: sticky; top: 0; z-index: 2; }
.compare-table tbody tr:first-child > * { border-top: 0; }
.compare-table thead th.phone-name { font: 700 1.02em/1.25 Manrope, sans-serif; color: #1e2a40; vertical-align: bottom; }
.compare-table thead th.phone-name small { display: block; margin-top: .2em; font: 400 .72em 'DM Sans', sans-serif; color: var(--muted); }
.compare-table .spec-label {
  position: sticky;
  left: 0;
  z-index: 1;
  border-left: 0;
  background: #f9fafc;
  color: #4a5670;
  font-size: .8em;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  box-shadow: inset -1px 0 0 #d5dbe6;
}
.compare-table thead th.corner { z-index: 3; background: #eef1f7; }
.compare-table tbody tr:hover td, .compare-table tbody tr:hover th.spec-label { background: #eaf0ff; }
.compare-table a { color: var(--accent); font-weight: 700; text-decoration: none; }
.compare-table a:hover { text-decoration: underline; }

.rank { display: inline-block; margin-top: .3em; max-width: 100%; font-size: .82em; font-weight: 700; padding: .12em .6em; border-radius: 20px; background: #eef1f8; color: #66738a; }
.rank-1 { background: #dcf5e6; color: #11703d; }
.rank-2 { background: #e3f4d9; color: #3d6e14; }
.rank-3 { background: #e9efff; color: #2c52c9; }
.rank-4 { background: #fff1d6; color: #8a5a00; }
.rank-5 { background: #ffe6d5; color: #a24a0f; }
.rank-6 { background: #fdeaea; color: #a33b3b; }

/* ---- Popup ------------------------------------------------------------ */
.dialog {
  width: min(560px, calc(100vw - 24px));
  border: 1px solid #e7eaf2;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 50px #27345c33;
  color: #172033;
}
.dialog::backdrop { background: #1b25384d; }
.dialog label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.dialog textarea {
  width: 100%;
  min-height: 200px;
  max-height: 60vh;
  resize: vertical;
  border: 1px solid #dce1ec;
  border-radius: 9px;
  padding: 12px;
  font: 14px/1.7 'DM Sans', sans-serif;
  color: #1b2740;
  outline: none;
}
.dialog textarea:focus { border-color: #6684ed; box-shadow: 0 0 0 3px #315ee815; }
.dialog .error { margin-top: 10px; }
.form-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; color: #566176; font-size: 12.5px; }
.dialog-buttons { display: flex; gap: 8px; }

@media (max-width: 560px) {
  .compare-table col.label-col { width: 5.5em; }
  .compare-table .spec-label { text-transform: none; letter-spacing: 0; font-size: .85em; }
  .button { padding: 8px 10px; font-size: 12px; }
  .form-bottom { flex-direction: column; align-items: stretch; }
  .dialog-buttons { justify-content: flex-end; }
}

/* ---- Results area: table + pager -------------------------------------- */
.results-area { height: 100%; display: flex; flex-direction: column; gap: 8px; }
.results-area .table-wrap { height: auto; flex: 1; min-height: 0; touch-action: pan-y pinch-zoom; }
.pager { flex: none; display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 13px; color: #53617a; }
.pager-button { min-width: 44px; height: 38px; padding: 0 12px; font-size: 20px; line-height: 1; }

/* ---- Phones (portrait) ------------------------------------------------- */
@media (max-width: 560px) {
  .wide-only { display: none; }
  .app { padding: 8px 8px 8px; gap: 6px; }
  .actions { gap: 6px; }
  .button { padding: 8px 12px; min-height: 36px; }
  .info-button { width: 36px; height: 36px; }
  /* Tooltip becomes a full-width panel under the top bar so it never goes off-screen. */
  .info-wrap { position: static; }
  .info-tip { position: fixed; top: 54px; left: 8px; right: 8px; width: auto; max-height: calc(100dvh - 70px); }
  /* Popup fills most of the screen; buttons are easy to tap. */
  .dialog { width: calc(100vw - 16px); max-width: none; max-height: calc(100dvh - 16px); padding: 16px; }
  .dialog textarea { min-height: min(220px, 40dvh); max-height: 50dvh; font-size: 16px; } /* 16px stops iOS zooming in */
  .dialog-buttons { display: grid; grid-template-columns: 1fr 2fr; }
  .dialog-buttons .button { min-height: 44px; }
}

/* ---- Very narrow phones ------------------------------------------------ */
@media (max-width: 360px) {
  .bar h1 { font-size: 14px; }
  .button { padding: 7px 9px; font-size: 12px; }
}

/* ---- Phones in landscape / short screens -------------------------------- */
@media (max-height: 500px) {
  .app { padding-top: 6px; padding-bottom: 6px; gap: 6px; }
  .bar { min-height: 34px; }
  .button { padding: 6px 10px; min-height: 32px; }
  .info-button { width: 32px; height: 32px; }
  .pager-button { height: 32px; }
  .dialog textarea { min-height: 120px; max-height: 45dvh; }
}

/* ---- Popup tabs: Find / Lookup ----------------------------------------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 16px; background: #eef1f7; border-radius: 10px; }
.tab { border: 0; border-radius: 7px; padding: 9px 12px; background: transparent; color: #56637a; font-weight: 700; font-size: 14px; cursor: pointer; }
.tab[aria-selected="true"] { background: #fff; color: var(--accent); box-shadow: 0 1px 3px #27345c26; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.panel[hidden] { display: none; }
#panel-find { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#panel-find[hidden] { display: none; }
.field label { margin-bottom: 6px; }
.field select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #dce1ec;
  border-radius: 9px;
  background: #fff;
  color: #1b2740;
  font: 14px 'DM Sans', sans-serif;
  outline: none;
}
.field select:focus { border-color: #6684ed; box-shadow: 0 0 0 3px #315ee815; }
.invisible { visibility: hidden; }
@media (max-width: 560px) {
  #panel-find { grid-template-columns: 1fr; }
  .field select { font-size: 16px; min-height: 44px; }
  .form-bottom .invisible { display: none; }
}
