:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #162033;
  --muted: #6b7588;
  --line: #dce3ee;
  --green: #23a26d;
  --blue: #2563eb;
  --amber: #d8901d;
  --red: #dc3f4d;
  --nav: #12233d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 264px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: var(--nav);
  color: #eaf1fb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #36c28f;
  color: #082017;
  font-weight: 800;
}

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

.brand span,
.sidebar-footer span {
  color: #9eb0ca;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: #c9d5e7;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.nav-item.active,
.nav-item:hover {
  background: #203553;
  color: #ffffff;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: #66d3a5;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border: 1px solid #2d4260;
  border-radius: 8px;
  background: #172b49;
}

.sidebar-footer strong {
  display: block;
  margin-top: 4px;
}

.app {
  min-height: 100vh;
  margin-left: 264px;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(360px, 34vw);
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  font: inherit;
}

button,
select {
  font: inherit;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  padding: 0 16px;
  background: var(--blue);
  color: #ffffff;
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  display: none;
  width: 42px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--red);
  cursor: pointer;
  font-weight: 800;
}

.summary-grid,
.content-grid,
.work-grid {
  display: grid;
  gap: 16px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(17, 31, 54, 0.06);
}

.metric-card {
  padding: 18px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 30px;
  line-height: 1;
}

small {
  color: var(--muted);
}

.positive {
  color: var(--green);
}

.warning {
  color: var(--amber);
}

.content-grid {
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  margin-bottom: 16px;
}

.work-grid {
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.9fr);
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: end;
  gap: 14px;
  height: 238px;
  padding: 18px 8px 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#eef3fa 1px, transparent 1px) 0 0 / 100% 25%;
}

.chart span {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 28px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, #36c28f, #2563eb);
}

.chart span.empty-bar {
  min-height: 0;
  background: transparent;
  border-top: 2px solid var(--line);
}

.chart span strong {
  position: absolute;
  top: -22px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.chart-labels {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  padding: 10px 8px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.donut-wrap {
  display: grid;
  place-items: center;
  gap: 18px;
  min-height: 276px;
}

.donut {
  width: 184px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(
    var(--green) 0 var(--active-stop),
    var(--amber) var(--active-stop) var(--expiring-stop),
    var(--red) var(--expiring-stop) 100%
  );
  position: relative;
}

.donut::after {
  content: attr(data-total);
  position: absolute;
  inset: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  font-size: 26px;
  font-weight: 800;
}

.legend {
  display: grid;
  gap: 9px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.green { background: var(--green); }
.amber { background: var(--amber); }
.red { background: var(--red); }

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
}

.badge.due {
  background: #fff4d8;
  color: #92600d;
}

.badge.ready {
  background: #dcf7eb;
  color: #11764d;
}

.badge.danger {
  background: #ffe3e6;
  color: #a72835;
}

.ticket-list {
  display: grid;
  gap: 12px;
}

.ticket {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ticket strong {
  font-size: 14px;
}

.ticket p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.priority {
  color: var(--red);
  font-weight: 800;
  font-size: 12px;
}

.muted-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.form-section {
  grid-column: 1 / -1;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.form-section-head {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-section-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.form-section-field {
  display: grid;
  gap: 6px;
}

.required-mark {
  color: var(--red);
}

.product-description-input {
  min-height: 110px;
  resize: vertical;
}

.product-multi-box {
  margin-top: 6px;
  width: 100%;
}

.product-multi-box .product-multi-select,
.form-grid .product-multi-select {
  display: block;
  width: 100%;
  min-height: 42px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  appearance: auto;
  -webkit-appearance: menulist;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr);
  gap: 16px;
}

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

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-grid input,
.form-grid select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.form-section-field input[data-contract-site] {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.site-pick-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.form-submit {
  align-self: end;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 24, 41, 0.46);
}

.modal {
  width: min(720px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  padding: 20px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(12, 24, 41, 0.28);
}

.modal .icon-button {
  display: inline-grid;
  width: auto;
  padding: 0 12px;
}

.action-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px 12px;
  align-items: center;
}

.action-list span {
  color: var(--muted);
  font-size: 14px;
}

.action-list strong {
  color: var(--green);
  font-size: 14px;
}

.login-mode .sidebar,
.login-mode .app {
  display: none;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(35, 162, 109, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(37, 99, 235, 0.12), transparent 38%),
    var(--bg);
}

.login-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(17, 31, 54, 0.14);
}

.login-brand {
  margin-bottom: 24px;
  color: var(--ink);
}

.login-card h1 {
  margin-bottom: 8px;
}

.login-help {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
}

.login-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffe3e6;
  color: #a72835;
  font-weight: 800;
  font-size: 13px;
}

.user-admin-panel {
  grid-column: 1 / -1;
}

.user-table {
  margin-top: 18px;
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid,
  .work-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .sidebar {
    position: static;
    width: auto;
    min-height: auto;
    padding: 16px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

  .app {
    margin-left: 0;
    padding: 16px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    align-items: start;
    padding: 12px;
  }

  h1 {
    font-size: 23px;
  }
}

.nav-icon svg { width: 20px; height: 20px; display: block; }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(12, 24, 41, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  display: grid;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
}

.toast {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(17, 31, 54, 0.14);
  font-size: 14px;
  font-weight: 700;
  animation: toast-in 0.25s ease;
}

.toast.success { border-color: #b8ebd6; background: #ecfbf4; color: #11764d; }
.toast.error { border-color: #f5c2c8; background: #fff0f2; color: #a72835; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-state {
  text-align: center;
  padding: 28px 16px !important;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 15px;
}

.empty-state .primary-button {
  margin-top: 14px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.action-buttons .ghost-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.status-select {
  min-width: 130px;
  height: 32px;
  font-size: 13px;
  font-weight: 700;
}

.renewal-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #f0d9a8;
  border-radius: 8px;
  background: #fff8e8;
  color: #7a5510;
  font-size: 14px;
  font-weight: 700;
}

.days-left {
  font-weight: 800;
}

.days-left.urgent { color: var(--red); }
.days-left.soon { color: var(--amber); }

.menu-button { display: none; }

@media (max-width: 780px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    z-index: 18;
    transform: translateX(-110%);
    transition: transform 0.22s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .app {
    margin-left: 0;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    width: auto;
  }

  .nav-list {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sidebar,
  .sidebar-overlay,
  .menu-button,
  .toast-host,
  #newButton,
  #logoutButton,
  .search,
  .ghost-button,
  .text-button,
  .action-buttons,
  .status-select,
  [data-export] {
    display: none !important;
  }

  .app {
    margin-left: 0 !important;
    padding: 0 !important;
  }

  body {
    background: #ffffff;
  }

  .panel,
  .metric-card {
    box-shadow: none;
    break-inside: avoid;
  }
}

.product-tab {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #c4b5fd;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #f5f3ff, #e9e5ff);
  color: #4338ca;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.form-grid textarea {
  width: 100%;
  min-height: 88px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}

.form-grid .field-full {
  grid-column: 1 / -1;
}


.reports-layout { display: grid; gap: 16px; }
.list-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
  padding: 14px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.filter-control {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  min-width: 160px;
}
.filter-control select,
.filter-control input[type="date"] {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.report-controls .report-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.report-controls .filter-control { min-width: 0; }
.report-actions { grid-column: 1 / -1; display: flex; gap: 10px; }
.report-document { padding: 28px; }
.report-header { border-bottom: 2px solid var(--nav); padding-bottom: 16px; margin-bottom: 20px; }
.report-company { font-size: 22px; font-weight: 800; }
.report-meta { color: var(--muted); font-size: 13px; }
.report-customer-card { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 20px; }
.report-amc-block { margin-bottom: 24px; break-inside: avoid; }
.report-amc-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.report-amc-tab { font-size: 12px; margin-right: 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th, .report-table td { border: 1px solid var(--line); padding: 10px; text-align: left; }
.report-table th { background: #eef3fa; font-size: 11px; text-transform: uppercase; }
.report-empty { color: var(--muted); font-style: italic; padding: 12px; }
.report-summary { margin-top: 8px; font-weight: 700; }
.no-print { }

@media print {
  body.printing-report .sidebar,
  body.printing-report .topbar,
  body.printing-report .report-controls,
  body.printing-report .no-print { display: none !important; }
  body.printing-report .app { margin: 0; padding: 0; }
  body.printing-report .report-document { box-shadow: none; border: 0; }
}

.login-portal-link {
  margin-top: 16px;
  text-align: center;
  font-size: 0.9rem;
}

.login-portal-link a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

.login-portal-link a:hover {
  text-decoration: underline;
}

.report-type-help { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.report-summary-table .count-cell { text-align: center; font-weight: 700; }
.report-summary-table .count-total { background: #ecfbf4; color: #11764d; font-size: 15px; }
.report-totals-row { background: #f4f7fb; }
.report-totals-row td { border-top: 2px solid var(--nav); }

.sites-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.site-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
}

.site-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

@media (max-width: 760px) {
  .site-row {
    grid-template-columns: 1fr;
  }
}
