/* ==========================================================================
   Portal layout — extends tokens from style.css
   ========================================================================== */
body.portal { background: var(--bg); }

.portal-shell { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.portal-sidebar {
  width: 248px; flex: none; background: var(--bg-elevated); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 300;
  transition: transform .25s ease;
}
.portal-brand { display: flex; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.portal-brand img { height: 44px; width: auto; }
.portal-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.portal-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: 14.5px; font-weight: 600; color: var(--text-secondary); transition: background .15s, color .15s;
}
.portal-nav a svg { width: 18px; height: 18px; flex: none; }
.portal-nav a:hover { background: var(--overlay-tint); color: var(--text); }
.portal-nav a.active { background: var(--brand-crimson); color: #fff; }
.portal-sidebar-foot { padding: 16px; border-top: 1px solid var(--border); }
.portal-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--chip-tint); color: var(--brand-crimson);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; font-size: 14px; flex: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 68px; height: 68px; font-size: 24px; }
.portal-user .who { min-width: 0; }
.portal-user .name { font-size: 13.5px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-user .email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-logout { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.portal-logout:hover { color: var(--brand-crimson); }
.portal-logout svg { width: 15px; height: 15px; }

/* ---- Main ---- */
.portal-main { flex: 1; margin-left: 248px; min-width: 0; }
.portal-topbar {
  position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.portal-topbar h1 { font-size: 21px; }
.portal-topbar-actions { display: flex; align-items: center; gap: 14px; }
.portal-menu-toggle { display: none; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elevated); align-items: center; justify-content: center; }
.portal-menu-toggle svg { width: 18px; height: 18px; }
.bell-btn { position: relative; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-elevated); display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.bell-btn svg { width: 17px; height: 17px; }
.bell-btn .dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-signal); border: 2px solid var(--bg-elevated); }
.portal-content { padding: 28px 32px 64px; max-width: 1180px; }

.portal-sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(20,10,12,.4); z-index: 250; }

@media (max-width: 980px) {
  .portal-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .portal-sidebar.is-open { transform: translateX(0); }
  .portal-main { margin-left: 0; }
  .portal-menu-toggle { display: flex; }
  .portal-sidebar-scrim.is-open { display: block; }
  .portal-content { padding: 22px 18px 48px; }
  .portal-topbar { padding: 14px 18px; }
}

/* ---- Flash message ---- */
.flash { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; margin-bottom: 22px; }
.flash-success { background: color-mix(in srgb, var(--status-up) 12%, var(--bg-elevated)); color: var(--status-up); border: 1px solid color-mix(in srgb, var(--status-up) 30%, transparent); }
.flash-error { background: color-mix(in srgb, var(--status-error) 12%, var(--bg-elevated)); color: var(--status-error); border: 1px solid color-mix(in srgb, var(--status-error) 30%, transparent); }

/* ---- Cards / grid ---- */
.p-grid { display: grid; gap: 20px; }
.p-grid-2 { grid-template-columns: 1.3fr 1fr; }
.p-grid-3 { grid-template-columns: repeat(3, 1fr); }
.p-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .p-grid-2, .p-grid-3, .p-grid-4 { grid-template-columns: 1fr; } }

.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; }
.card-tight { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-head h3 { font-size: 16px; }
.card-head .muted-link { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.card-head .muted-link:hover { color: var(--brand-crimson); }

/* ---- Stat tiles ---- */
.stat-tile .lbl { font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }
.stat-tile .val { margin-top: 8px; font-family: var(--font-display); font-size: 28px; font-weight: 700; }
.stat-tile .sub { margin-top: 4px; font-size: 13px; color: var(--text-secondary); }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-up { background: color-mix(in srgb, var(--status-up) 14%, transparent); color: var(--status-up); }
.badge-warn { background: color-mix(in srgb, var(--status-warn) 14%, transparent); color: var(--status-warn); }
.badge-error { background: color-mix(in srgb, var(--status-error) 14%, transparent); color: var(--status-error); }
.badge-info { background: color-mix(in srgb, var(--status-info) 14%, transparent); color: var(--status-info); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.p-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.p-table th { text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: 0 12px 10px; border-bottom: 1px solid var(--border); }
table.p-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary); vertical-align: middle; }
table.p-table tr:last-child td { border-bottom: none; }
table.p-table td.strong { color: var(--text); font-weight: 600; }

/* ---- Buttons (small set specific to portal, reuse .btn from style.css) ---- */
.btn-xs { padding: 7px 13px; font-size: 12.5px; }
.btn-danger-ghost { background: transparent; border: 1px solid color-mix(in srgb, var(--status-error) 40%, var(--border)); color: var(--status-error); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--status-error) 10%, transparent); }

/* ---- Forms ---- */
.p-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .p-form-grid { grid-template-columns: 1fr; } }
.p-field { display: flex; flex-direction: column; gap: 6px; }
.p-field.full { grid-column: 1 / -1; }
.p-field label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
.p-field input, .p-field select, .p-field textarea {
  padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 14.5px; font-family: var(--font-body);
}
.p-field input:focus, .p-field select:focus, .p-field textarea:focus { outline: none; border-color: var(--brand-crimson); }
.p-field .hint { font-size: 12px; color: var(--text-muted); }
.p-field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }

/* ---- Toggle switch ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background .2s; cursor: pointer; }
.switch .track::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: var(--shadow-sm); }
.switch input:checked + .track { background: var(--brand-crimson); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- Usage chart ---- */
.usage-chart-wrap { position: relative; height: 220px; }
.usage-chart-wrap canvas { width: 100%; height: 100%; }
.legend-row { display: flex; gap: 20px; margin-top: 14px; flex-wrap: wrap; }
.legend-row .item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.legend-row .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ---- Plan comparison ---- */
.plan-compare-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; background: var(--bg); position: relative; }
.plan-compare-card.current { border-color: var(--brand-crimson); background: var(--overlay-tint); }
.plan-compare-card .current-tag { position: absolute; top: -11px; left: 18px; background: var(--brand-crimson); color: #fff; font-size: 10.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Device list ---- */
.device-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.device-row:last-child { border-bottom: none; }
.device-row .dev-ic { width: 36px; height: 36px; border-radius: 9px; background: var(--overlay-tint); color: var(--brand-crimson); display: flex; align-items: center; justify-content: center; flex: none; }
.device-row .dev-ic svg { width: 18px; height: 18px; }
.device-row .dev-name { font-size: 14px; font-weight: 600; color: var(--text); }
.device-row .dev-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.device-row .dev-status { margin-left: auto; }

/* ---- Notifications ---- */
.notif-item { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--overlay-tint); margin: 0 -20px; padding: 14px 20px; border-radius: var(--radius-sm); }
.notif-ic { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
.notif-ic svg { width: 16px; height: 16px; }
.notif-title { font-size: 14px; font-weight: 700; color: var(--text); }
.notif-msg { font-size: 13.5px; color: var(--text-secondary); margin-top: 3px; }
.notif-time { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---- Tickets / thread ---- */
.msg-bubble { max-width: 78%; padding: 12px 15px; border-radius: 14px; font-size: 14px; line-height: 1.5; }
.msg-row { display: flex; margin-bottom: 14px; }
.msg-row.from-customer { justify-content: flex-end; }
.msg-row.from-customer .msg-bubble { background: var(--brand-crimson); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.from-support .msg-bubble { background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-meta { font-size: 11px; margin-top: 5px; opacity: .7; }

/* ---- Speed test dial ---- */
.speedtest-box { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 12px 0 4px; }
.speedtest-result { font-family: var(--font-display); font-size: 44px; font-weight: 700; color: var(--brand-crimson); }
.speedtest-result span { font-size: 15px; color: var(--text-muted); font-weight: 600; margin-left: 4px; }

/* ---- Utility ---- */
.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
