:root {
  --navy: #153b5a;
  --blue: #2074b9;
  --orange: #ee7623;
  --bg: #f3f7f9;
  --line: #dce6ea;
  --text: #193743;
  --muted: #6b7f87;
  --green: #12845e;
  --red: #b83e48;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Arial, sans-serif;
}

body { overflow-x: hidden; }

button,
input,
select,
textarea { font: inherit; }

button,
a,
input,
select,
textarea { touch-action: manipulation; }

:focus-visible {
  outline: 3px solid #f6a15f;
  outline-offset: 2px;
}

.hidden,
[hidden] { display: none !important; }

.center-card {
  width: min(470px, calc(100% - 32px));
  margin: 12vh auto;
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 20px 70px #173c5920;
  text-align: center;
}

.center-card p { color: var(--muted); }

.center-card small {
  display: block;
  margin-top: 18px;
  color: var(--muted);
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, var(--blue), var(--navy));
  font-size: 24px;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--orange) !important;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .09em;
}

.shell { min-height: 100vh; }

aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: 245px;
  padding: 24px 18px;
  color: #fff;
  background: var(--navy);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 25px;
}

.brand .brand-mark {
  width: 38px;
  height: 38px;
  margin: 0;
  font-size: 18px;
}

.brand b,
.brand span { display: block; }

.brand span {
  color: #b9cad5;
  font-size: 11px;
}

.official-brand {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(220, 230, 234, .92);
  background: #fff;
}

.official-brand img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

.official-brand-center {
  width: min(260px, 100%);
  height: 49px;
  margin: 0 auto 18px;
  border-radius: 13px;
  box-shadow: 0 12px 28px rgba(21, 59, 90, .10);
}

.official-sidebar-brand {
  display: block;
  padding: 0 8px 18px;
  text-align: center;
}

.official-brand-sidebar {
  width: 100%;
  height: 38px;
  border-color: rgba(255, 255, 255, .50);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
}

.official-sidebar-brand > span {
  margin-top: 7px;
  color: #c9d7df;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
}

nav {
  display: grid;
  gap: 5px;
}

nav button {
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  color: #d9e6ed;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

nav button:hover,
nav button.active {
  color: #fff;
  background: #ffffff17;
  box-shadow: inset 3px 0 var(--orange);
}

.security {
  position: absolute;
  right: 18px;
  bottom: 22px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px;
  border-radius: 10px;
  background: #ffffff0d;
}

.security i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2dd99b;
}

.security b,
.security span { display: block; }

.security span {
  color: #aac0cd;
  font-size: 10px;
}

.workspace {
  margin-left: 245px;
  min-width: 0;
}

.workspace > header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 17px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.workspace > header div { margin-left: auto; }

.workspace > header b,
.workspace > header span {
  display: block;
  text-align: right;
}

.workspace > header span {
  color: var(--muted);
  font-size: 10px;
}

.icon-button { display: none; }

.view {
  display: none;
  padding: 30px;
}

.view.active { display: block; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 0;
  font-size: 30px;
}

.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.button,
.small-button,
.dialog-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: #fff;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.button.secondary { background: #f8fafb; }

.button.danger {
  border-color: #e4b7bb;
  color: var(--red);
  background: #fff5f5;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.metric span,
.metric strong { display: block; }

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  margin-top: 7px;
  font-size: 23px;
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 8px 30px #153b5a0c;
}

.panel h2 { margin: 0 0 15px; }
.table-wrap { overflow: auto; }

.subscriber-history {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafb;
  min-width: 0;
}
.subscriber-history[hidden] { display: none; }
.subscriber-history h3 { margin: 0 0 8px; font-size: 15px; }
.subscriber-history .form-note { margin: 4px 0 8px; }
.subscriber-history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.subscriber-history-item { padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; overflow-wrap: anywhere; }
.subscriber-history-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.subscriber-history-top time { margin-left: auto; color: var(--muted); font-size: 11px; }
.subscriber-history-item p { margin: 7px 0 4px; font-size: 12px; }
.subscriber-history-item small { color: var(--muted); }
.subscriber-history .button { margin-top: 10px; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid #edf2f4;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .04em;
}

td { font-size: 12px; }

.empty-row td {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.small-button {
  min-height: 28px;
  padding: 0 8px;
  color: var(--blue);
  font-size: 10px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.team-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--orange);
  border-radius: 14px;
  background: #fff;
}

.team-card small,
.team-card code { color: var(--muted); }

.team-card h2 {
  margin: 7px 0;
  font-size: 17px;
}

.team-workload {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 14px 0;
}

.team-workload span,
.team-workload strong {
  display: block;
  text-align: center;
}

.team-workload span {
  grid-row: 1;
  color: var(--muted);
  font-size: 9px;
}

.team-workload strong {
  grid-row: 2;
  padding: 7px 3px;
  border-radius: 8px;
  color: var(--navy);
  background: #edf5f9;
  font-size: 18px;
}

.team-card .small-button { width: 100%; }

.work-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -9px 0 16px;
}

.legend-dot,
.priority-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.legend-dot::before {
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  content: "";
  background: currentColor;
}

.legend-dot.priority-normal,
.priority-badge.priority-normal { color: #1767a4; }
.legend-dot.priority-high,
.priority-badge.priority-high { color: #a84f10; }
.legend-dot.priority-critical,
.priority-badge.priority-critical { color: #a52531; }
.priority-badge.priority-normal { background: #e8f3fb; }
.priority-badge.priority-high { background: #fff0e5; }
.priority-badge.priority-critical { background: #ffe8ea; }

.work-row.priority-normal td:first-child { border-left: 3px solid #62a7d7; }
.work-row.priority-high td:first-child { border-left: 3px solid var(--orange); }
.work-row.priority-critical td:first-child { border-left: 3px solid var(--red); }
.work-row.work-row-closed { background: #e9f7ef; }
.work-row.work-row-cancelled { background: #fff0f0; }
.work-row.work-row-postponed { background: #fff8d9; }
.work-row.work-row-closed td:first-child { border-left-color: #159466; }
.work-row.work-row-cancelled td:first-child { border-left-color: #ce424e; }
.work-row.work-row-postponed td:first-child { border-left-color: #d5a321; }

.status-pool { color: #536a74; background: #edf2f4; }
.status-assigned { color: #155d90; background: #e6f2fa; }
.status-en_route { color: #895a00; background: #fff3cf; }
.status-in_progress { color: #7043a0; background: #f2eafa; }
.status-customer_approval { color: #8c5b0a; background: #fff0d4; }
.status-customer_approved { color: #08704e; background: #e4f6ee; }
.status-customer_rejected,
.status-cancelled { color: #9a303a; background: #ffebed; }
.status-closed { color: #08704e; background: #e4f6ee; }
.status-field-completed { color: #8c5b0a; background: #fff0d4; }
.status-detail { display: block; margin-top: 3px; color: #536a74; font-size: 0.72rem; }
.status-postponed { color: #795900; background: #fff3c4; }

.permission-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.permission-group {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.permission-group legend {
  padding: 0 6px;
  color: var(--navy);
  font-weight: 800;
}

.permission-check {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 36px;
  color: var(--text);
}

.permission-check input { width: auto; }

.compact-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0;
}

.alert {
  position: fixed;
  top: 82px;
  right: 24px;
  max-width: 440px;
  padding: 13px 16px;
  border: 1px solid #efc0c4;
  border-radius: 10px;
  color: #8f2731;
  background: #fff1f2;
  z-index: 30;
}

.toast {
  position: fixed;
  right: 25px;
  bottom: 25px;
  padding: 14px 18px;
  border-radius: 10px;
  color: #fff;
  background: var(--green);
  opacity: 0;
  transform: translateY(15px);
  transition: .2s;
  pointer-events: none;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: none;
}

dialog {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 25px 80px #102f4660;
}

dialog::backdrop { background: #102f4675; }

dialog form {
  display: grid;
  gap: 14px;
  padding: 24px;
}

dialog h2 { margin: 0 0 4px; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #cad8de;
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}

textarea {
  min-height: 85px;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.approval-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.approval-card {
  width: min(540px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 20px 70px #173c5920;
  text-align: center;
}

.approval-card h1 { margin: 10px 0 24px; }

.approval-card span,
.approval-card strong { display: block; }

.approval-card span {
  color: var(--muted);
  font-size: 11px;
}

.approval-card strong {
  margin: 5px 0 18px;
  font-size: 20px;
}

.approval-card #approvalSummary {
  padding: 18px;
  border-radius: 12px;
  background: #f4f8fa;
  text-align: left;
}

.approval-card small { color: var(--muted); }

.approval-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.privacy {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.result {
  padding: 18px;
  border-radius: 12px;
}

.result.success {
  color: #096b4b;
  background: #e6f6ef;
}

.result.error {
  color: #962f39;
  background: #fff0f1;
}

/* Compact boolean controls used by administration dialogs. */
.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
}

.check-row input {
  width: auto;
  margin: 0;
}

@media (max-width: 1050px) {
  .metrics,
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  aside {
    width: min(86vw, 320px);
    padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    transform: translateX(-100%);
    transition: .2s;
    box-shadow: 18px 0 42px #102f4655;
  }

  body::before {
    position: fixed;
    inset: 0;
    content: "";
    background: #102f4675;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 9;
  }

  .menu-open::before {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-open aside { transform: none; }
  nav button { min-height: 48px; }

  .security {
    position: static;
    margin-top: 18px;
  }

  .workspace { margin-left: 0; }
  .icon-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--navy);
    background: #fff;
    font-size: 22px;
  }

  .workspace > header {
    position: sticky;
    top: 0;
    height: auto;
    min-height: calc(64px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    gap: 9px;
    z-index: 8;
  }

  .workspace > header div {
    min-width: 0;
    overflow: hidden;
  }

  .workspace > header b,
  .workspace > header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace > header .button { min-width: 64px; }
  .view { padding: 20px 14px; }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .page-head h1 { font-size: 26px; }

  .page-head > button,
  .page-head > div:last-child:not(:first-child),
  .page-head > div:last-child:not(:first-child) .button { width: 100%; }

  .page-head > div:last-child:not(:first-child) {
    display: grid;
    gap: 8px;
  }

  .metrics,
  .card-grid,
  .approval-actions,
  .permission-options { grid-template-columns: 1fr; }

  .compact-metrics { grid-template-columns: repeat(2, 1fr); }

  .panel { padding: 12px; }

  .table-wrap { overflow: visible; }

  table { min-width: 0; }

  table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  table tbody {
    display: grid;
    gap: 12px;
  }

  table tbody tr {
    display: block;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--orange);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 5px 18px #153b5a0b;
  }

  table tbody td {
    display: grid;
    grid-template-columns: minmax(92px, 36%) 1fr;
    gap: 10px;
    padding: 10px 0;
    overflow-wrap: anywhere;
  }

  table tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
  }

  table tbody .empty-row {
    border-left-color: var(--line);
  }

  table tbody .empty-row td {
    display: block;
    padding: 22px 0;
  }

  table tbody .empty-row td::before { content: none; }

  table tbody td.actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button,
  .small-button,
  .dialog-actions button {
    min-height: 44px;
    font-size: 14px;
  }

  input,
  select,
  textarea {
    min-height: 46px;
    font-size: 16px;
  }

  textarea { min-height: 112px; }

  dialog {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
  }

  dialog form,
  .detail-card {
    max-height: 92dvh;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: sticky;
    bottom: 0;
    padding-top: 8px;
    background: #fff;
  }

  .alert,
  .toast {
    right: 12px;
    left: 12px;
    max-width: none;
  }

  .toast { bottom: calc(12px + env(safe-area-inset-bottom)); }

  .approval-card { padding: 24px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
