/* Prism — Linear-Light. Light mode, Inter throughout, indigo accent. */

:root {
    --bg:        #FBFBFA;
    --surface:   #FFFFFF;
    --surface-2: #F8F8F7;
    --surface-3: #F2F2F0;
    --hairline:  #E8E8E6;
    --hairline-strong: #DCDCD9;
    --text:      #1F2023;
    --text-mute: #5C5E63;
    --text-dim:  #9A9DA3;
    --accent:    #5E6AD2;
    --accent-hover: #4D5BC7;
    --phosphor:  #3AA76D;  /* "online" / success — green */
    --amber:     #D9920E;  /* "idle" / warning */
    --coral:     #D44C47;  /* "offline" / danger */
    --ink:       #2A2C30;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 13.5px;
    line-height: 1.5;
    letter-spacing: -0.005em;
    font-feature-settings: "ss01", "cv05", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

.serif { font-family: "Inter", sans-serif; font-weight: 600; letter-spacing: -0.02em; }

.label {
    font-family: "Inter", sans-serif;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-mute);
}

/* ---- top bar ---- */
header.top {
    border-bottom: 1px solid var(--hairline);
    background: var(--surface);
    position: sticky; top: 0; z-index: 10;
}
header.top .inner {
    max-width: 1480px; margin: 0 auto; padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
    font-family: "Inter", sans-serif;
    font-weight: 600;
    font-size: 17px;
    color: var(--text);
    letter-spacing: -0.02em;
    display: inline-flex; align-items: center; gap: 6px;
}
.brand .mark::before {
    content: ""; width: 14px; height: 14px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--accent), #8589DC);
}
.brand .crumb {
    font-size: 12px; color: var(--text-mute);
    border-left: 1px solid var(--hairline-strong); padding-left: 12px;
    margin-left: 4px;
}
.brand .crumb a:hover { color: var(--text); }

nav.top-nav { display: flex; gap: 2px; align-items: center; }
nav.top-nav a {
    padding: 6px 12px;
    font-size: 13px; font-weight: 500;
    color: var(--text-mute);
    border-radius: 5px;
    transition: color 0.12s, background 0.12s;
}
nav.top-nav a:hover { color: var(--text); background: var(--surface-2); }
nav.top-nav a.active { color: var(--text); background: var(--surface-2); }

.who { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-mute); }
.who .me {
    color: var(--text); padding: 5px 11px;
    border: 1px solid var(--hairline-strong);
    border-radius: 5px; cursor: pointer;
    font-weight: 500; font-size: 12px;
    transition: border-color 0.12s, background 0.12s;
}
.who .me:hover { border-color: var(--accent); background: rgba(94,106,210,0.04); }
.who .me.empty { color: var(--coral); border-color: rgba(212,76,71,0.3); }
.who .me.empty:hover { background: rgba(212,76,71,0.04); }

/* ---- section rail ---- */
main { max-width: 1480px; margin: 0 auto; padding: 24px 24px 60px; }

.section-rail {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 12px;
    border-bottom: 1px solid var(--hairline);
}
.section-rail h2 {
    font-family: "Inter", sans-serif;
    font-weight: 600;
    font-size: 22px;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0;
}
.section-rail .meta { font-size: 12px; color: var(--text-mute); }

/* ---- controls ---- */
.controls {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-bottom: 16px; align-items: center;
}
.controls > .search { flex: 1 1 280px; min-width: 0; }
.controls > .count-badge { margin-left: auto; }

.search { position: relative; display: flex; align-items: center; }
.search input {
    width: 100%; background: var(--surface);
    border: 1px solid var(--hairline-strong);
    border-radius: 6px;
    color: var(--text);
    padding: 10px 12px 10px 32px;
    /* 16px prevents iOS Safari auto-zoom on focus. */
    font: 400 16px/1.4 "Inter", sans-serif;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--text-dim); }
.search input:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(94,106,210,0.12);
}
.search::before {
    content: ""; position: absolute; left: 11px;
    width: 14px; height: 14px;
    background: no-repeat center/contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%239A9DA3' stroke-width='1.6'><circle cx='7' cy='7' r='5'/><line x1='10.5' y1='10.5' x2='14' y2='14' stroke-linecap='round'/></svg>");
}

.filter-group {
    display: flex; gap: 0;
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    border-radius: 6px;
    padding: 2px;
}
.filter-group button {
    background: transparent; border: none;
    color: var(--text-mute);
    padding: 5px 10px;
    font: 500 12px "Inter", sans-serif;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.1s, background 0.1s;
    display: inline-flex; align-items: center; gap: 6px;
}
.filter-group button:hover { color: var(--text); }
.filter-group button.active { color: var(--text); background: var(--surface-2); box-shadow: 0 0 0 1px var(--hairline) inset; }
.filter-group button .swatch { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }

.count-badge { font-size: 12px; color: var(--text-mute); font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 4px; }
.count-badge .n { color: var(--text); font-weight: 500; }

/* ---- table ---- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
thead th {
    text-align: left; padding: 9px 14px;
    font-weight: 500; font-size: 11px;
    letter-spacing: 0.02em;
    color: var(--text-mute);
    background: var(--surface-2);
    border-bottom: 1px solid var(--hairline);
    user-select: none; cursor: pointer; white-space: nowrap;
    position: sticky; top: 0;
    transition: color 0.12s;
}
thead th:hover { color: var(--text); }
thead th[data-sort="asc"]::after,
thead th[data-sort="desc"]::after { content: ""; display: inline-block; margin-left: 6px; border-left: 3px solid transparent; border-right: 3px solid transparent; vertical-align: middle; opacity: 0.7; }
thead th[data-sort="asc"]::after  { border-bottom: 4px solid var(--accent); }
thead th[data-sort="desc"]::after { border-top:    4px solid var(--accent); }
.right { text-align: right !important; }
.center { text-align: center !important; }

tbody tr {
    border-top: 1px solid var(--hairline);
    transition: background 0.06s;
    cursor: pointer;
}
tbody tr:first-child { border-top: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td {
    padding: 9px 14px;
    vertical-align: middle;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
td.id {
    color: var(--text); font-weight: 500;
    font-family: "ui-monospace", "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
}
td.unit { color: var(--text); }
td.condo { color: var(--text-mute); font-size: 12px; }
td.energy { color: var(--text); font-family: "ui-monospace", "SF Mono", Menlo, monospace; font-size: 12.5px; }
td.mute { color: var(--text-mute); }
td.dim { color: var(--text-dim); }

/* status dot */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot.online  { background: var(--phosphor); }
.dot.idle    { background: var(--amber); }
.dot.offline { background: var(--coral); }
.dot.never   { background: var(--text-dim); opacity: 0.5; }
.dot.poor    { background: var(--coral); }

.live { display: inline-flex; align-items: center; gap: 6px; color: var(--text-mute); font-size: 12px; }
.live::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: var(--phosphor);
}

/* sim cell */
.sim { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sim .icc {
    color: var(--text);
    font-family: "ui-monospace", "SF Mono", Menlo, monospace;
    font-size: 11.5px;
    white-space: nowrap;
}
.sim .prov { color: var(--text-dim); font-size: 11px; }
.sim .warn { width: 6px; height: 6px; border-radius: 50%; background: var(--coral); }

/* badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 7px;
    font-size: 11px; font-weight: 500;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-mute);
    border: 1px solid var(--hairline);
}
.badge.green  { background: #E6F4EC; color: #1F7A4D; border-color: #C9E5D5; }
.badge.amber  { background: #FCEFD3; color: #8C5A0C; border-color: #F0DAA9; }
.badge.red    { background: #FDE8E7; color: #9C322F; border-color: #F4C9C7; }
.badge.indigo { background: #EEEFFB; color: #3D47A6; border-color: #D8DBF4; }
.badge .dot-i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* flag chips: small letter inside a tile */
.flags { display: inline-flex; gap: 4px; align-items: center; }
.flag {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 4px;
    font-size: 10px; font-weight: 600;
    border-radius: 3px;
    background: var(--surface-2);
    color: var(--text-mute);
    border: 1px solid var(--hairline);
}
.flag.r { background: #FDE8E7; color: #9C322F; border-color: #F4C9C7; }
.flag.u { background: #E6F4EC; color: #1F7A4D; border-color: #C9E5D5; }
.flag.p { background: #FCEFD3; color: #8C5A0C; border-color: #F0DAA9; }

/* relative-time */
.rel { font-size: 12px; color: var(--text-mute); }
.rel .now { color: var(--phosphor); font-weight: 500; }
.rel .recent { color: var(--text); }

.dim { color: var(--text-dim); }

/* skeleton/empty */
.skeleton-row td { color: var(--text-dim); font-style: italic; }
.empty { padding: 60px 16px; text-align: center; color: var(--text-dim); }
.empty .big { font-weight: 600; font-size: 18px; color: var(--text-mute); margin-bottom: 4px; }

.empty-mini { color: var(--text-dim); font-size: 13px; padding: 12px 0; }

/* footer */
.footer-note { margin-top: 20px; font-size: 11px; color: var(--text-dim); text-align: right; }

/* ---- buttons / forms ---- */
button.btn, .btn {
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    color: var(--text);
    padding: 6px 12px;
    font: 500 12.5px "Inter", sans-serif;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
    line-height: 1.3;
    display: inline-flex; align-items: center; gap: 6px;
}
button.btn:hover { background: var(--surface-2); border-color: var(--text-dim); }
button.btn.primary { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }
button.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.btn.danger { color: var(--coral); border-color: rgba(212,76,71,0.3); }
button.btn.danger:hover { background: var(--coral); color: #FFFFFF; border-color: var(--coral); }
button.btn:disabled { opacity: 0.4; cursor: not-allowed; }

input.txt, textarea.txt, select.txt {
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    color: var(--text);
    padding: 8px 11px;
    /* 16px prevents iOS Safari auto-zoom on focus. */
    font: 400 16px "Inter", sans-serif;
    border-radius: 6px;
    width: 100%;
    transition: border-color 0.12s, box-shadow 0.12s;
}
@media (min-width: 700px) {
    input.txt, textarea.txt, select.txt { font-size: 13px; padding: 7px 11px; }
}
input.txt:focus, textarea.txt:focus, select.txt:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(94,106,210,0.12);
}
textarea.txt { resize: vertical; min-height: 64px; line-height: 1.5; }
label.fld { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
label.fld .l { font-size: 11px; font-weight: 500; color: var(--text-mute); }

.toast-shelf {
    position: fixed; bottom: 20px; right: 20px; z-index: 100;
    display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text);
    border-radius: 6px;
    border-left: 3px solid var(--accent);
    animation: slideIn 0.18s ease-out;
}
.toast.error { border-left-color: var(--coral); color: var(--coral); }
.toast.success { border-left-color: var(--phosphor); }
@keyframes slideIn {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---- modal ---- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(31,32,35,0.4);
    z-index: 50; display: none; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 24px 26px;
    max-width: 480px; width: 92%; max-height: 88vh; overflow-y: auto;
    box-shadow: 0 24px 48px rgba(0,0,0,0.12);
}
.modal h3 {
    font-family: "Inter", sans-serif;
    font-weight: 600; font-size: 17px;
    color: var(--text); letter-spacing: -0.01em;
    margin: 0 0 6px;
}
.modal p { color: var(--text-mute); margin: 0 0 18px; font-size: 13px; line-height: 1.5; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---- autocomplete ---- */
.ac-wrap { position: relative; }
.ac-wrap > .txt { padding-right: 28px; }
.ac-wrap::after {
    content: "";
    position: absolute; right: 10px; top: 50%;
    width: 7px; height: 7px;
    border-right: 1.5px solid var(--text-mute);
    border-bottom: 1.5px solid var(--text-mute);
    transform: translate(0, -70%) rotate(45deg);
    pointer-events: none;
}
.ac-pop {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    border-top: none;
    z-index: 20;
    max-height: 280px; overflow-y: auto;
    box-shadow: 0 12px 24px rgba(0,0,0,0.08);
    display: none;
}
.ac-item {
    padding: 7px 10px;
    cursor: pointer;
    border-bottom: 1px dotted var(--hairline);
    font-size: 13px;
    color: var(--text);
}
.ac-item:last-child { border-bottom: none; }
.ac-item.active, .ac-item:hover { background: var(--surface-2); }
.ac-item .ac-label { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.ac-item .ac-sub { color: var(--text-mute); font-size: 11px; margin-top: 2px; }
.ac-item.ac-create { color: var(--accent); font-weight: 500; font-family: "Inter", sans-serif; }

/* ---- responsive ---- */
@media (min-width: 700px) {
    .search input { font-size: 13px; padding: 8px 12px 8px 32px; }
}
@media (max-width: 960px) {
    main { padding: 16px 14px 50px; }
    header.top .inner { padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
    nav.top-nav { order: 3; flex-basis: 100%; justify-content: center; }
    .controls { grid-template-columns: 1fr; }
}

/* iPhone notch / Dynamic Island safe-area padding for full-bleed sections. */
@supports (padding: max(0px)) {
    header.top .inner { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
    main { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
}

/* :hover only fires on devices with a real cursor (kills sticky-hover on touch). */
@media (hover: none) {
    button.btn:hover, .btn:hover { background: var(--surface); border-color: var(--hairline-strong); }
    tbody tr:hover { background: transparent; }
    nav.top-nav a:hover { background: transparent; color: var(--text-mute); }
    .filter-group button:hover { color: var(--text-mute); }
}

/* Touch-friendly tap targets on phones. */
@media (max-width: 700px) {
    button.btn, .btn { padding: 11px 16px; font-size: 14px; min-height: 44px; }
    .filter-group button { padding: 10px 14px; font-size: 13px; min-height: 40px; }
    nav.top-nav a { padding: 10px 14px; }

    /* Hide low-priority list columns on phone (still in horizontal scroll if needed). */
    .col-sim, .col-readcount, .col-comments, .col-photos { display: none; }

    /* Larger row hit area in tables. */
    tbody td { padding: 12px 12px; }
    thead th  { padding: 11px 12px; }
}

/* Tightest phones: drop condo + secondary signals too. */
@media (max-width: 480px) {
    .col-condo { display: none; }
}
