/* ==========================================================================
   MailControl — authenticated app shell + product UI
   Extends css/styles.css (tokens, buttons, pills, panel, htable, kpis,
   chart-svg, codeblock, timeline, incident, fail-row, seg, toggle).
   Layout + app-only components here.
   ========================================================================== */

/* --------------------------------------------------------------------------
   App layout grid
   -------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.app__sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
  z-index: 40;
}
.app__brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px 16px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.app__nav-group { margin-top: 6px; }
.app__nav-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-secondary);
  padding: 14px 10px 8px;
}
.app__nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  font-size: 13.5px;
  color: var(--fg-secondary);
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.app__nav-item:hover { background: var(--muted); color: var(--fg); }
.app__nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.app__nav-item.is-active {
  background: var(--muted);
  color: var(--fg);
  font-weight: 500;
}
.app__nav-item .badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid #ECCAC6;
}
.app__nav-item .badge.is-info { background: var(--accent-soft); color: var(--accent); border-color: #CBE0D6; }

.app__side-foot { margin-top: auto; padding-top: 16px; }
.app__plan {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--muted);
  margin-bottom: 10px;
}
.app__plan .t { font-size: 12px; font-weight: 600; }
.app__plan .d { font-size: 11.5px; color: var(--fg-secondary); margin-top: 3px; font-family: var(--font-mono); }
.app__plan a { display: inline-block; margin-top: 9px; font-size: 12px; font-weight: 500; color: var(--accent); }
.app__signout {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--fg-secondary);
  border-radius: var(--radius-sm);
  width: 100%;
}
.app__signout:hover { background: var(--muted); color: var(--fg); }
.app__signout svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------------------
   Main column
   -------------------------------------------------------------------------- */
.app__main { display: flex; flex-direction: column; min-width: 0; }

.app__topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 60px;
  padding: 0 22px;
  background: rgba(247, 247, 244, 0.85);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.app__hamburger {
  display: none;
  width: 38px; height: 38px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.app__hamburger svg { width: 18px; height: 18px; }

/* workspace switcher */
.ws-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  position: relative;
  transition: border-color 0.12s;
}
.ws-switch:hover { border-color: #C5CBBE; }
.ws-switch .ws-mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}
.ws-switch .chev { margin-left: 2px; color: var(--fg-secondary); }
.ws-switch .chev svg { width: 13px; height: 13px; }

.ws-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 50;
}
.ws-menu.is-open { display: block; }
.ws-menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.ws-menu__item:hover { background: var(--muted); }
.ws-menu__item.is-active { background: var(--accent-soft); }
.ws-menu__item .ws-mark { width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; color: #fff; font-family: var(--font-mono); font-size: 11px; }
.ws-menu__sep { height: 1px; background: var(--border); margin: 5px 0; }
.ws-menu__item .sub { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--fg-secondary); }

/* search */
.app__search {
  flex: 1;
  max-width: 420px;
  position: relative;
}
.app__search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.app__search input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.app__search > svg {
  position: absolute;
  left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--fg-secondary);
}
.app__search kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px;
  color: var(--fg-secondary); background: var(--muted);
}

.app__topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.app__status {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 10px;
  font-family: var(--font-mono); font-size: 11.5px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--fg-secondary);
}
.app__status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: pulse 2.4s ease-in-out infinite; }
.app__icon-btn {
  position: relative;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg-secondary);
}
.app__icon-btn:hover { color: var(--fg); border-color: #C5CBBE; }
.app__icon-btn svg { width: 17px; height: 17px; }
.app__icon-btn .count {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  background: var(--error); color: #fff;
  border-radius: 999px;
  font-size: 10px; font-weight: 600;
  display: grid; place-items: center;
  font-family: var(--font-sans);
  border: 2px solid var(--bg);
}
.app__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--fg);
  color: #fff;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 600;
  letter-spacing: 0.01em;
}

/* content */
.app__content {
  padding: 28px 28px 64px;
  max-width: 1240px;
  width: 100%;
}
.app__page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.app__page-head h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.app__page-head .sub { font-size: 13.5px; color: var(--fg-secondary); margin-top: 4px; font-family: var(--font-mono); }
.app__page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Cards / sections
   -------------------------------------------------------------------------- */
.app__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.app__card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.app__card-head .t { font-size: 13.5px; font-weight: 600; letter-spacing: -0.005em; }
.app__card-head .t .count { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-secondary); font-weight: 400; margin-left: 6px; }
.app__card-body { padding: 16px; }
.app__card-body--flush { padding: 0; }

.app__grid-2 { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(0,1fr); gap: 18px; }
.app__grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }

/* greeting */
.greet { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.greet .h { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.greet .meta { font-size: 12.5px; color: var(--fg-secondary); font-family: var(--font-mono); }
.greet .meta .dot { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--border); margin: 0 8px 2px; vertical-align: middle; }

/* KPI trend in app */
.app__kpi-delta { font-size: 11px; font-family: var(--font-mono); margin-top: 3px; color: var(--success); }
.app__kpi-delta.is-warn { color: var(--warning); }
.app__kpi-delta.is-flat { color: var(--fg-secondary); }

/* action queue */
.queue { display: grid; gap: 10px; }
.queue__item {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.12s;
}
.queue__item:hover { border-color: #C5CBBE; }
.queue__item .sev {
  width: 8px; height: 8px; border-radius: 50%;
}
.queue__item .sev.s-error { background: var(--error); }
.queue__item .sev.s-warn { background: var(--warning); }
.queue__item .sev.s-info { background: var(--accent); }
.queue__item .body { min-width: 0; }
.queue__item .body .t { font-size: 13px; font-weight: 500; }
.queue__item .body .t strong { font-weight: 600; }
.queue__item .body .d { font-size: 12px; color: var(--fg-secondary); margin-top: 2px; font-family: var(--font-mono); }
.queue__item .act { font-size: 12.5px; font-weight: 500; color: var(--accent); white-space: nowrap; }
.queue__item .act:hover { color: var(--accent-hover); }

/* mini activity (dashboard) */
.mini-act { display: grid; gap: 0; }
.mini-act__row {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.mini-act__row:last-child { border-bottom: 0; }
.mini-act__row .nd { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.mini-act__row.is-muted .nd { background: var(--border); }
.mini-act__row .ev { min-width: 0; }
.mini-act__row .ev .t { color: var(--fg); }
.mini-act__row .ev .a { font-family: var(--font-mono); font-size: 11px; color: var(--fg-secondary); }
.mini-act__row time { font-family: var(--font-mono); font-size: 11px; color: var(--fg-secondary); }

/* quick actions */
.qa { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.qa__item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.12s, transform 0.12s;
}
.qa__item:hover { border-color: var(--accent); transform: translateY(-1px); }
.qa__item .ico { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.qa__item .ico svg { width: 16px; height: 16px; }
.qa__item .t { font-size: 13px; font-weight: 600; }
.qa__item .d { font-size: 11.5px; color: var(--fg-secondary); }

/* provider distribution bars */
.dist { display: grid; gap: 9px; }
.dist__row { display: grid; grid-template-columns: 90px 1fr 44px; gap: 10px; align-items: center; font-size: 12px; }
.dist__row .k { color: var(--fg-secondary); font-family: var(--font-mono); font-size: 11.5px; }
.dist__row .bar { height: 8px; background: var(--muted); border-radius: 4px; overflow: hidden; }
.dist__row .bar i { display: block; height: 100%; border-radius: 4px; }
.dist__row .v { font-family: var(--font-mono); text-align: right; font-size: 11.5px; }

/* --------------------------------------------------------------------------
   Toolbar (filters/chips/search above tables)
   -------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 11px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-secondary);
  transition: all 0.12s;
}
.chip:hover { border-color: #C5CBBE; color: var(--fg); }
.chip.is-active { background: var(--fg); color: #fff; border-color: var(--fg); }
.chip .c { font-family: var(--font-mono); font-size: 10.5px; margin-left: 5px; opacity: 0.7; }

.toolbar__search {
  position: relative;
  margin-left: auto;
}
.toolbar__search input {
  padding: 7px 11px 7px 30px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 220px;
}
.toolbar__search input:focus { outline: 0; border-color: var(--accent); }
.toolbar__search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; color: var(--fg-secondary); }

/* table extras */
.table-wrap { overflow-x: auto; }
.htable--app th, .htable--app td { padding: 11px 16px; }
.htable--app .row-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.htable--app .row-actions a { font-size: 12px; color: var(--accent); font-weight: 500; }
.htable--app tbody tr { cursor: pointer; }
.htable--app tbody tr:hover { background: var(--muted); }
.htable--app .checkbox { width: 15px; height: 15px; }

/* skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--muted) 25%, var(--surface) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: 4px;
}
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* --------------------------------------------------------------------------
   Drawer (right detail panel)
   -------------------------------------------------------------------------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(17, 19, 16, 0.4);
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 80;
}
.scrim.is-open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 90;
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }
.drawer__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer__head .t { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; word-break: break-all; }
.drawer__head .d { font-size: 12px; color: var(--fg-secondary); font-family: var(--font-mono); margin-top: 3px; }
.drawer__close {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  flex-shrink: 0;
}
.drawer__close:hover { background: var(--muted); color: var(--fg); }
.drawer__close svg { width: 17px; height: 17px; }

.drawer__tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.drawer__tab {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--fg-secondary);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
}
.drawer__tab:hover { color: var(--fg); }
.drawer__tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

.drawer__body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer__panel { display: none; }
.drawer__panel.is-active { display: block; }

.drawer__section + .drawer__section { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }
.drawer__section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-secondary); margin-bottom: 11px; font-family: var(--font-mono); font-weight: 500; }

/* DNS record row inside drawer */
.rec {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 10px;
}
.rec__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px;
  background: #FCFCFB;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.rec__head .name { font-family: var(--font-mono); font-weight: 500; }
.rec__head .type { font-family: var(--font-mono); font-size: 10.5px; padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px; color: var(--fg-secondary); }
.rec__val { padding: 10px 12px; font-family: var(--font-mono); font-size: 11.5px; color: var(--fg); word-break: break-all; line-height: 1.6; }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal {
  position: fixed; inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  z-index: 100;
}
.modal.is-open { display: grid; }
.modal__box {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal__head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal__head .t { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal__head .d { font-size: 12.5px; color: var(--fg-secondary); margin-top: 3px; }
.modal__body { padding: 20px; }
.modal__foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: #FCFCFB; }

/* stepper inside modal */
.steps { display: flex; gap: 0; margin-bottom: 20px; }
.steps__step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.steps__step::before { content: ""; position: absolute; top: 13px; left: -50%; right: 50%; height: 1px; background: var(--border); z-index: 0; }
.steps__step:first-child::before { display: none; }
.steps__step .n {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--fg-secondary);
  position: relative; z-index: 1;
}
.steps__step.is-active .n { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps__step.is-done .n { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps__step .l { font-size: 10.5px; color: var(--fg-secondary); text-align: center; font-family: var(--font-mono); }
.steps__step.is-active .l { color: var(--fg); }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast-wrap {
  position: fixed;
  bottom: 22px; right: 22px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 16px;
  background: var(--fg);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  max-width: 340px;
  transform: translateY(12px); opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
}
.toast.is-visible { transform: translateY(0); opacity: 1; }
.toast .ico { width: 18px; height: 18px; flex-shrink: 0; color: #8BBFAB; }
.toast.is-error .ico { color: #E08B82; }

/* --------------------------------------------------------------------------
   Mobile bottom tab bar
   -------------------------------------------------------------------------- */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 45;
}
.tabbar__item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px;
  font-size: 10px;
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.tabbar__item svg { width: 19px; height: 19px; }
.tabbar__item.is-active { color: var(--accent); }
.tabbar { display: flex; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .app__sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 60;
    box-shadow: var(--shadow-lg);
  }
  .app__sidebar.is-open { transform: translateX(0); }
  .app__hamburger { display: grid; }
  .app__content { padding: 20px 18px 84px; }
  .app__grid-2, .app__grid-3 { grid-template-columns: 1fr; }
  .qa { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app__topbar { padding: 0 14px; gap: 10px; }
  .app__search { display: none; }
  .app__status .lbl { display: none; }
  .app__page-head h1 { font-size: 22px; }
  .toolbar__search { margin-left: 0; width: 100%; }
  .toolbar__search input { width: 100%; }
  .drawer { width: 100%; }
  .modal__box { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton, .app__status .dot, .toast { animation: none !important; transition: none !important; }
}
