:root {
  --navy: #233067;
  --blue: #4569E3;
  --mint: #84D4B9;
  --gold: #DBB840;
  --slate: #6D7582;
  --red: #C0392B;
  --white: #FFFFFF;
  --bg: #F4F6F9;
  --border: #E2E6ED;
  --text: #1F2937;
  --muted: #6D7582;
  --shadow: 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

body { overflow-x: hidden; }

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

button { cursor: pointer; }

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

a, button, input, select, textarea {
  outline-color: var(--blue);
}

img { max-width: 100%; display: block; }

.hidden { display: none !important; }

.screen, .view { display: none; }
.screen.active, .view.active { display: block; }

.loading-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--white);
  z-index: 1000;
}

.loading-box {
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--border);
  background: var(--white);
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow);
}

.loading-logo { width: 56px; margin: 0 auto 16px; }
.loading-box h1 { margin: 0 0 8px; color: var(--navy); font-size: 24px; }
.loading-box p { margin: 0; color: var(--muted); }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 420px;
  gap: 40px;
  align-items: center;
  padding: 48px;
  background: var(--bg);
}

.login-brand {
  max-width: 620px;
}

.brand-logo-wide {
  width: 320px;
  max-height: 96px;
  object-fit: contain;
  object-position: left center;
  margin-bottom: 32px;
}

.brand-text-fallback {
  display: grid;
  line-height: 1.2;
}

.brand-text-fallback strong {
  color: var(--navy);
  font-size: 18px;
}

.brand-text-fallback span {
  color: var(--slate);
  font-size: 12px;
}

.login-brand h1 {
  margin: 0 0 12px;
  color: var(--navy);
  font-size: clamp(32px, 4vw, 48px);
  line-height: 1.1;
  letter-spacing: 0;
}

.login-brand p {
  margin: 0;
  color: var(--blue);
  font-size: 20px;
  font-weight: 700;
}

.login-card, .panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.login-card {
  padding: 32px;
}

.login-card-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  margin-bottom: 24px;
}

.form-field {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

label, .filters label {
  color: var(--slate);
  font-size: 13px;
  font-weight: 700;
}

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

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

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(69,105,227,.16);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

.button {
  min-height: 38px;
  border-radius: 4px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
}

.button.primary {
  background: var(--blue);
  color: var(--white);
}

.button.primary:hover { background: #3859C4; }

.button.secondary {
  background: var(--white);
  border-color: var(--border);
  color: var(--navy);
}

.button.secondary:hover { border-color: var(--blue); color: var(--blue); }

.button.danger {
  background: var(--white);
  border-color: var(--red);
  color: var(--red);
}

.button.text {
  background: transparent;
  border: 0;
  color: var(--blue);
  padding-inline: 4px;
}

.full-width { width: 100%; }

.demo-panel {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.demo-title {
  margin: 0 0 8px;
  color: var(--navy);
  font-weight: 700;
}

.demo-account {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  text-align: left;
}

.error-message {
  min-height: 20px;
  margin: 0 0 12px;
  color: var(--red);
  font-weight: 700;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 72px;
  padding: 0 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.nav-logo {
  width: 220px;
  height: 52px;
  object-fit: contain;
  object-position: left center;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--navy);
  font-weight: 700;
}

.role-chip, .status-badge, .priority-badge, .yes-no {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.role-chip {
  color: var(--navy);
  background: var(--bg);
  border: 1px solid var(--border);
}

.workspace {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.sidebar {
  background: var(--navy);
  border-right: 1px solid var(--navy);
}

.primary-nav {
  display: grid;
  gap: 4px;
  padding: 16px;
}

.nav-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: rgba(255,255,255,.82);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
}

.nav-button:hover, .nav-button.active {
  background: var(--blue);
  color: var(--white);
}

.content {
  min-width: 0;
  padding: 28px;
}

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

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

h2 {
  margin: 0;
  color: var(--navy);
  font-size: 28px;
  line-height: 1.2;
}

h3 {
  margin: 0;
  color: var(--navy);
  font-size: 17px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 4px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.kpi-card.open { border-left-color: var(--slate); }
.kpi-card.progress { border-left-color: var(--gold); }
.kpi-card.closed { border-left-color: var(--mint); }
.kpi-card.reportable { border-left-color: var(--red); }

.kpi-label {
  margin: 0 0 8px;
  color: var(--slate);
  font-size: 13px;
  font-weight: 700;
}

.kpi-value {
  margin: 0;
  color: var(--navy);
  font-size: 32px;
  font-weight: 800;
}

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

.panel {
  margin-bottom: 16px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.chart-wrap {
  height: 300px;
  padding: 18px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  background: var(--bg);
  color: var(--slate);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

td { color: var(--text); }

tbody tr:hover td { background: #FAFBFC; }

.status-open { background: #F1F3F5; color: var(--slate); }
.status-in-progress { background: #FBF4D8; color: #7A6319; }
.status-closed { background: #E6F6F1; color: #2F6D5C; }
.priority-high { background: #F8E6E3; color: var(--red); }
.priority-medium { background: #FBF4D8; color: #7A6319; }
.priority-low { background: #E6F6F1; color: #2F6D5C; }
.yes-no.yes { background: #F8E6E3; color: var(--red); }
.yes-no.no { background: var(--bg); color: var(--slate); }

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

.form-panel { padding: 18px; }

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

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

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

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr);
  gap: 16px;
}

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

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

.detail-label {
  display: block;
  color: var(--slate);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

.detail-value {
  margin: 0;
  color: var(--text);
}

.detail-form {
  padding: 18px;
  border-top: 1px solid var(--border);
}

.timeline {
  padding: 4px 18px 18px;
}

.timeline-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child { border-bottom: 0; }

.timeline-item strong { color: var(--navy); }
.timeline-item p { margin: 4px 0 0; color: var(--slate); font-size: 13px; }

.filters {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto minmax(140px, .4fr) auto minmax(140px, .4fr);
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

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

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--navy);
  color: var(--white);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-only { display: none; }

.icon-button {
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--navy);
  border-radius: 4px;
  min-height: 38px;
  padding: 8px 10px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .inline-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }

  .login-shell {
    grid-template-columns: 1fr;
    padding: 24px;
  }

  .login-brand h1 { font-size: 32px; }
  .brand-logo-wide { width: 260px; }

  .topbar {
    height: auto;
    min-height: 72px;
    align-items: flex-start;
    padding: 12px 16px;
    flex-direction: column;
  }

  .topbar-user {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .nav-logo { width: 180px; }

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

  .sidebar {
    display: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar.open { display: block; }

  .content { padding: 20px 16px; }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .kpi-grid, .chart-grid, .form-grid, .details-grid, .detail-list, .settings-grid {
    grid-template-columns: 1fr;
  }

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

  .form-field.wide, .detail-item.wide { grid-column: auto; }

  .form-actions { justify-content: stretch; flex-direction: column; }
  .form-actions .button { width: 100%; }

  .chart-wrap { height: 260px; }
}

@media (max-width: 480px) {
  .login-card { padding: 24px; }
  .kpi-grid { grid-template-columns: 1fr; }
  h2 { font-size: 24px; }
  .button { width: 100%; }
  .table-actions .button { width: auto; }
}
