:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6b7890;
  --line: #dce3ee;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --soft: #eef2ff;
  --shadow: 0 10px 30px rgba(22, 31, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: linear-gradient(135deg, #4f46e5, #14b8a6);
  font-weight: 800;
  letter-spacing: 0;
}

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

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

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

.nav-link {
  display: block;
  padding: 12px 14px;
  border-radius: 8px;
  color: #334155;
  font-weight: 600;
}

.nav-link.active,
.nav-link:hover {
  color: var(--primary-dark);
  background: var(--soft);
  text-decoration: none;
}

.main {
  margin-left: 280px;
  padding: 34px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.entry-head {
  display: grid;
  gap: 10px;
  justify-items: start;
  margin-bottom: 24px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  color: #344054;
  background: #e9eef7;
  font-weight: 800;
}

.back-link:hover {
  color: var(--primary-dark);
  background: var(--soft);
  text-decoration: none;
}

.head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  padding: 20px;
}

.metric span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.metric strong {
  font-size: 25px;
}

.panel {
  margin-bottom: 24px;
  padding: 22px;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(360px, 0.9fr);
  gap: 24px;
}

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

.recent-records {
  align-self: start;
  padding: 0;
  overflow: hidden;
}

.recent-records summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 22px;
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
  list-style: none;
  user-select: none;
}

.recent-records summary::-webkit-details-marker {
  display: none;
}

.recent-records summary:hover {
  background: #f8faff;
}

.recent-records-arrow {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  transform: rotate(90deg);
  transition: transform 0.18s ease, color 0.18s ease;
}

.recent-records[open] .recent-records-arrow {
  color: var(--primary);
  transform: rotate(-90deg);
}

.recent-records-table {
  overflow-x: auto;
  padding: 0 22px 22px;
  border-top: 1px solid var(--line);
}

.recent-records-table table {
  margin-top: 14px;
}

.ai-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 14px;
}

.ai-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #f8fbff;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

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

.ai-card em {
  color: #d92d20;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.ai-card span {
  margin-top: 8px;
  color: var(--text);
  font-weight: 700;
}

.ai-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h2,
.section-head .hint {
  margin-bottom: 0;
}

.inline-filter select {
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

.ai-scope-form {
  align-items: flex-end;
}

.copy-box {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fbff;
  color: var(--text);
  font: 13px/1.55 Consolas, "Courier New", monospace;
}

.report-rendered {
  line-height: 1.6;
}

.report-rendered h3,
.report-rendered h4,
.report-rendered h5 {
  margin: 18px 0 10px;
}

.report-rendered ul {
  padding-left: 22px;
}

.risk-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  background: #eef2ff;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

.risk-critical,
.risk-high {
  background: #fee2e2;
  color: #b91c1c;
}

.risk-medium {
  background: #fef3c7;
  color: #92400e;
}

.risk-low {
  background: #dcfce7;
  color: #166534;
}

.ai-metadata-panel .detail-grid strong {
  line-height: 1.45;
}

.report-table {
  overflow-x: auto;
  margin: 14px 0;
}

.manual-ai-box {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.manual-ai-box summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 260px 1fr;
  align-items: center;
  gap: 26px;
  min-height: 300px;
}

.donut {
  width: 240px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.05);
}

.donut::after {
  content: "";
  position: absolute;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--panel);
}

.donut span {
  position: relative;
  z-index: 1;
  color: var(--text);
  font-size: 28px;
  font-weight: 900;
}

.donut-svg {
  width: 240px;
  aspect-ratio: 1;
  overflow: visible;
}

.donut-track,
.donut-segment {
  fill: none;
  stroke-width: 56;
}

.donut-track {
  stroke: #e2e8f0;
}

.donut-segment {
  cursor: pointer;
  transition: stroke-width 0.18s ease, opacity 0.18s ease;
}

.donut-segment:hover {
  stroke-width: 62;
  opacity: 0.88;
}

.donut-hole {
  fill: var(--panel);
}

.donut-svg text {
  fill: var(--text);
  font-size: 28px;
  font-weight: 900;
}

.chart-legend {
  display: grid;
  gap: 12px;
}

.chart-legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.chart-legend-row:hover {
  color: var(--primary-dark);
  text-decoration: none;
}

.chart-legend-row span:last-child {
  color: var(--muted);
  font-weight: 700;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.risk-list {
  display: grid;
  gap: 14px;
}

.risk-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(160px, 260px) 54px;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfdff;
}

.risk-row:hover {
  border-color: rgba(79, 70, 229, 0.45);
  background: var(--soft);
  text-decoration: none;
}

.risk-row strong,
.risk-row span {
  display: block;
}

.risk-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.risk-row b {
  text-align: right;
}

.risk-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.risk-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.risk-low {
  background: #10b981;
}

.risk-mid {
  background: #f59e0b;
}

.risk-high {
  background: #ef4444;
}

.form-panel {
  max-width: 720px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
}

.action-card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfdff;
}

.action-card:hover {
  border-color: rgba(79, 70, 229, 0.45);
  background: var(--soft);
  text-decoration: none;
}

.action-card strong {
  font-size: 17px;
}

.action-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.field-group {
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 16px;
}

.detail-grid div {
  display: grid;
  gap: 7px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.detail-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.detail-grid strong {
  font-size: 16px;
}

.detail-wide {
  grid-column: 1 / -1;
}

.notice {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e3a8a;
  background: #eff6ff;
  font-weight: 700;
}

.plain-text {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.grid {
  display: grid;
  gap: 20px;
  align-items: start;
}

.grid.two {
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
}

.wide {
  overflow-x: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.button:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.button.muted {
  color: #344054;
  background: #e9eef7;
}

.button.muted:hover {
  background: #dde5f2;
}

.button.danger {
  color: white;
  background: #dc2626;
}

.button.danger:hover {
  background: #991b1b;
}

.button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

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

.calc-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.calc-box div {
  display: grid;
  gap: 5px;
}

.calc-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.calc-box strong {
  color: #0f172a;
  font-size: 18px;
}

.inline-form {
  grid-template-columns: repeat(5, minmax(140px, 1fr)) auto;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: #40506a;
  font-size: 14px;
  font-weight: 650;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.checkbox-line input {
  width: auto;
  min-height: auto;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: white;
  font: inherit;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(79, 70, 229, 0.2);
  border-color: var(--primary);
}

input[readonly] {
  color: #1e3a8a;
  background: #eef4ff;
  font-weight: 800;
}

.mini-form {
  margin: 0;
}

.mini-form select {
  min-height: 34px;
  padding: 5px 8px;
}

.rate-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rate-form input {
  width: 110px;
  min-height: 34px;
  padding: 5px 8px;
}

.offer-edit-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.offer-edit-form select {
  width: 88px;
  min-height: 34px;
  padding: 5px 8px;
}

.offer-edit-form input {
  width: 110px;
  min-height: 34px;
  padding: 5px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #42526b;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:has(a[href]) {
  cursor: pointer;
}

tbody tr:has(a[href]):hover {
  background: #f8fbff;
}

.empty,
.hint {
  color: var(--muted);
}

.hint {
  margin: -6px 0 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-card {
  width: min(920px, 96vw);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
  padding: 24px;
}

.wide-modal {
  width: min(1120px, 96vw);
}

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

.modal-head h2 {
  margin: 4px 0 0;
  font-size: 24px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-grid div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #f8fafc;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-grid strong {
  font-size: 20px;
}

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

.price-up {
  color: #dc2626;
  font-weight: 800;
}

.price-down {
  color: #16a34a;
  font-weight: 800;
}

.price-same {
  color: #64748b;
  font-weight: 800;
}

.focus-panel {
  border-color: #8b7cf6;
  background: #fbfaff;
}

@media (max-width: 1100px) {
  .dashboard-charts,
  .donut-wrap {
    grid-template-columns: 1fr;
  }

  .donut-wrap {
    justify-items: center;
  }

  .risk-row {
    grid-template-columns: 1fr;
  }

  .risk-row b {
    text-align: left;
  }

  .sidebar {
    position: static;
    width: auto;
  }

  .main {
    margin-left: 0;
    padding: 22px;
  }

  .metrics,
  .metrics.compact,
  .grid.two,
  .action-grid,
  .detail-grid,
  .inline-form,
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

.sidebar-user {
  margin-top: auto;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 5px;
  font-size: 13px;
}

.sidebar-user strong,
.sidebar-user span {
  overflow-wrap: anywhere;
}

.sidebar-user span {
  color: var(--muted);
}

.sidebar-user a {
  margin-top: 5px;
  color: var(--primary);
  font-weight: 800;
}

.local-mode {
  color: #166534 !important;
  font-weight: 800;
}

.auth-body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f2f5fa;
}

.auth-card {
  width: min(460px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 55px rgba(15, 23, 42, 0.12);
}

.auth-card h1 {
  margin: 28px 0 10px;
}

.auth-brand {
  margin: 0;
}

.auth-note,
.auth-error {
  margin: 18px 0;
  padding: 12px 14px;
  border-radius: 8px;
}

.auth-note {
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.auth-error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.google-button {
  display: block;
  margin-top: 20px;
  text-align: center;
}

.access-message {
  max-width: 680px;
}

.user-access-list {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.user-access-card {
  display: grid;
  gap: 18px;
}

.user-access-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.user-access-head h2,
.user-access-head p {
  margin: 0;
}

.user-access-head p {
  margin-top: 5px;
  color: var(--muted);
}

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

.permission-grid label,
.user-status {
  display: grid;
  gap: 6px;
}

.permission-grid span,
.user-status span {
  font-size: 13px;
  font-weight: 800;
  color: #42526b;
}

.status-badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-badge.owner,
.status-badge.active {
  color: #166534;
  background: #dcfce7;
}

.status-badge.pending {
  color: #92400e;
  background: #fef3c7;
}

.status-badge.blocked {
  color: #991b1b;
  background: #fee2e2;
}

@media (max-width: 900px) {
  .permission-grid {
    grid-template-columns: 1fr;
  }
}
