:root {
  --brand: #1b2d5b;
  --brand-700: #2a3f73;
  --brand-900: #0f1a38;
  --brand-soft: #e8eaf0;
  --ink: #2c3e50;
  --ink-2: #4a5568;
  --muted: #6b7c93;
  --line: #d1d5de;
  --panel: rgba(255, 255, 255, 0.95);
  --white: #ffffff;
  --bg: #f0f2f5;
  --green: #16805c;
  --green-soft: #e8f8f1;
  --amber: #a36512;
  --amber-soft: #fff4d8;
  --red: #b42318;
  --red-soft: #fff0ee;
  --shadow: 0 18px 50px rgba(27, 45, 91, 0.15);
  --shadow-sm: 0 10px 24px rgba(27, 45, 91, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(27, 45, 91, 0.08), transparent 34%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 42%, #e8eaf0 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(380px, 0.9fr);
  overflow: hidden;
}

.brand-panel {
  position: relative;
  min-height: 100vh;
  padding: 54px;
  color: var(--white);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(15, 26, 56, 0.98), rgba(27, 45, 91, 0.95)),
    url("data:image/svg+xml,%3Csvg width='220' height='220' viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.12'%3E%3Cpath d='M0 48h220M0 110h220M0 172h220M48 0v220M110 0v220M172 0v220'/%3E%3Ccircle cx='110' cy='110' r='58'/%3E%3C/g%3E%3C/svg%3E");
}

.brand-panel::after {
  content: "";
  position: absolute;
  inset: auto 54px 44px auto;
  width: 220px;
  height: 220px;
  border-radius: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  transform: rotate(8deg);
}

.login-logo {
  width: min(440px, 78%);
  max-height: 112px;
  object-fit: contain;
  object-position: left center;
  padding: 18px 22px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.70);
  box-shadow: 0 24px 70px rgba(36, 18, 44, 0.22);
}

.login-logos {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.login-logos .rab-logo {
  max-height: 90px;
  width: auto;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.70);
}

.login-logos .hachiai-logo {
  max-height: 80px;
  width: auto;
  padding: 12px 16px;
}

/* HachiAI Branding at Bottom Left */
.hachiai-branding {
  position: absolute;
  bottom: 40px;
  left: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.hachiai-branding .eyebrow {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--white);
  opacity: 1;
}

.hachiai-branding .hachiai-logo {
  max-height: 40px;
  width: auto;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.70);
}

.subtitle {
  margin: 0;
  max-width: 610px;
  color: #f4eaf8;
  font-size: clamp(24px, 2.5vw, 36px);
  font-weight: 650;
}

.login-panel {
  min-height: 100vh;
  padding: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: -28px 0 80px rgba(27, 45, 91, 0.12);
}

.login-panel h2,
.topbar h1,
.table-header h2,
.tool-panel h2 {
  margin: 0;
}

.login-panel h2 {
  font-size: 34px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 13px;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(76, 42, 87, 0.04);
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 4px solid rgba(27, 45, 91, 0.16);
}

.status-select {
  min-height: 34px;
  border-radius: 999px;
  padding: 6px 34px 6px 12px;
  font-size: 12px;
  font-weight: 950;
  color: var(--brand-900);
  background: var(--brand-soft);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 900;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.primary-btn {
  color: var(--white);
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  box-shadow: 0 14px 30px rgba(27, 45, 91, 0.28);
}

.secondary-btn {
  color: var(--brand-900);
  background: var(--brand-soft);
}

.danger-btn {
  color: var(--red);
  background: var(--red-soft);
}

.ghost-btn {
  color: var(--brand-900);
  background: rgba(255, 255, 255, 0.9);
}

.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  color: var(--white);
  background:
    linear-gradient(180deg, rgba(15, 26, 56, 0.99), rgba(27, 45, 91, 0.98)),
    url("data:image/svg+xml,%3Csvg width='150' height='150' viewBox='0 0 150 150' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 75h150M75 0v150' stroke='%23fff' stroke-opacity='.08'/%3E%3C/svg%3E");
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 24px 0 60px rgba(27, 45, 91, 0.15);
  transition: all 0.3s;
}

.side-brand {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  align-items: center;
}

.side-brand img {
  width: 100%;
  max-height: 48px;
  object-fit: contain;
  object-position: center;
  padding: 6px 8px;
}

.side-brand img {
  width: 100%;
  max-height: 58px;
  object-fit: contain;
  object-position: left center;
}

.side-brand span,
.session-card span {
  display: block;
  color: #b8c4d8;
  font-size: 12px;
  font-weight: 800;
}

.side-brand span {
  color: var(--brand-900);
}

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

.nav-btn {
  position: relative;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 11px 14px 11px 42px;
  color: #d8e0f0;
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
  font-weight: 900;
}

.nav-btn::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.34);
  transform: translateY(-50%);
}

.nav-btn.active,
.nav-btn:hover {
  color: var(--brand-900);
  background: var(--white);
  box-shadow: 0 12px 28px rgba(15, 26, 56, 0.2);
}

.nav-btn.active::before,
.nav-btn:hover::before {
  background: var(--brand);
}

.session-card {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.session-card .side-eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--white);
  opacity: 1;
}

.session-card strong {
  font-size: 18px;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 18px;
  margin: -26px -26px 22px;
  padding: 22px 26px;
  border-bottom: 1px solid rgba(235, 228, 238, 0.86);
  background: rgba(251, 248, 252, 0.88);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  font-size: clamp(24px, 2.4vw, 36px);
}

.topbar-logo {
  width: 170px;
  max-height: 48px;
  object-fit: contain;
}

.topbar-logos {
  display: flex;
  gap: 15px;
  align-items: center;
}

.topbar-logos .rab-logo {
  max-height: 40px;
  width: auto;
}

.topbar-logos .hachiai-logo {
  max-height: 44px;
  width: auto;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
}

.search-wrap {
  width: min(420px, 45vw);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metrics-grid article,
.table-card,
.tool-panel,
.inspector,
.rule-box,
.scope-box {
  border: 1px solid rgba(235, 228, 238, 0.9);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.metrics-grid article {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.column-controls {
  margin-bottom: 18px;
  display: flex;
  justify-content: flex-end;
}

.column-controls button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 8px 16px;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--white);
  border-radius: 20px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
  color: var(--brand-900);
}

.close-btn {
  background: none;
  border: none;
  font-size: 32px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s;
}

.close-btn:hover {
  background: var(--bg-soft);
}

.column-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
  max-height: 400px;
  overflow-y: auto;
}

.column-checkboxes label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
}

.column-checkboxes label:hover {
  background: var(--bg-soft);
}

.column-checkboxes input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 16px;
  border-top: 2px solid var(--line);
}

/* Sidebar Toggle */
.sidebar-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 10;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Expand Button (Floating) */
.sidebar-expand-btn {
  position: fixed;
  top: 180px;
  left: 20px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.sidebar-expand-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.9);
  transform: scale(1.1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.sidebar-expand-btn.hidden {
  display: none;
}

/* Loading Indicator */
.loading-indicator {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--bg-soft);
  border-radius: 10px;
  margin-top: 10px;
}

.loading-bar {
  width: 100%;
  height: 8px;
  background: rgba(147, 99, 165, 0.15);
  border-radius: 4px;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, var(--brand), var(--brand-light));
  border-radius: 4px;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    width: 30%;
    transform: translateX(-100%);
  }
  50% {
    width: 60%;
  }
  100% {
    width: 30%;
    transform: translateX(400%);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.loading-indicator span {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* Success Message */
.success-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 10px;
  margin-top: 10px;
  color: #16a34a;
  font-weight: 600;
  font-size: 14px;
  animation: slideIn 0.3s ease-out;
}

.success-message svg {
  flex-shrink: 0;
}

/* Error Message */
.error-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 10px;
  margin-top: 10px;
  color: #dc2626;
  font-weight: 600;
  font-size: 14px;
  animation: slideIn 0.3s ease-out;
}

.error-message svg {
  flex-shrink: 0;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  width: 0;
  padding: 0;
  overflow: hidden;
}

.workspace {
  transition: all 0.3s;
}

.metrics-grid article::after {
  content: "";
  position: absolute;
  right: -24px;
  bottom: -30px;
  width: 86px;
  height: 86px;
  border-radius: 24px;
  background: rgba(147, 99, 165, 0.11);
  transform: rotate(18deg);
}

.metrics-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metrics-grid strong {
  display: block;
  margin-top: 8px;
  color: var(--brand-900);
  font-size: 30px;
}

.table-card {
  overflow: hidden;
}

.table-header {
  min-height: 64px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(232, 234, 240, 0.62));
}

.table-header h2 {
  font-size: 19px;
}

.table-header span {
  color: var(--brand-700);
  font-size: 13px;
  font-weight: 900;
}

.table-scroll {
  overflow: auto;
  max-height: 58vh;
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: separate;
  border-spacing: 0;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--ink);
  background: #e8eaf0;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

td {
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.78);
}

td[contenteditable="true"] {
  background: #f8f9fb;
  box-shadow: inset 0 0 0 1px rgba(27, 45, 91, 0.24);
}

tbody tr:hover td {
  background: var(--brand-soft);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 11px;
  font-weight: 950;
  font-size: 12px;
}

.status-approved {
  color: var(--green);
  background: var(--green-soft);
}

.status-pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.row-actions button {
  min-height: 34px;
  border: 0;
  border-radius: 10px;
  padding: 7px 11px;
  color: var(--brand-900);
  background: var(--brand-soft);
  font-weight: 950;
}

.row-actions button.approve-action {
  color: var(--white);
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
}

.rules-footer {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(360px, 1.2fr) minmax(280px, 1fr);
  gap: 16px;
  margin-top: 18px;
}

.calculation-box {
  padding: 18px;
  border: 1px solid rgba(235, 228, 238, 0.9);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.calculation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border-radius: 14px;
  background: var(--brand-soft);
  font-size: 13px;
}

.calculation-row strong {
  color: var(--brand-900);
  font-size: 18px;
}

.rule-box,
.scope-box {
  padding: 18px;
}

.rule-box h3,
.scope-box h3,
.inspector h2 {
  margin: 0 0 12px;
}

.scope-box ul,
.rule-box ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.scope-box li {
  margin: 7px 0;
}

.rule-grid {
  display: grid;
  gap: 9px;
}

.rule-row {
  display: grid;
  grid-template-columns: 1.4fr 80px 1fr;
  gap: 10px;
  padding: 11px;
  border-radius: 14px;
  background: var(--brand-soft);
  font-size: 13px;
}

.rule-row strong {
  color: var(--brand-900);
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 16px;
}

.inspector {
  align-self: start;
  padding: 18px;
}

.inspector dl {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.inspector dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}

.inspector dd {
  margin: 3px 0 0;
  font-weight: 850;
  color: var(--ink);
}

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

.tool-panel {
  display: grid;
  gap: 13px;
  padding: 20px;
}

.tool-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.user-list,
.archive-list {
  display: grid;
  gap: 10px;
}

.user-row,
.archive-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  border: 1px solid rgba(147, 99, 165, 0.1);
  border-radius: 14px;
  background: var(--brand-soft);
}

.archive-row strong {
  display: block;
}

.archive-row span {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1120px) {
  .app-shell,
  .detail-layout,
  .rules-footer,
  .admin-grid {
    grid-template-columns: 1fr;
  }

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

  .side-brand {
    max-width: 320px;
  }

  .topbar {
    grid-template-columns: 1fr;
    position: static;
  }

  .topbar-logo {
    display: none;
  }

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

  .search-wrap {
    width: 100%;
  }
}

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

  .brand-panel,
  .login-panel {
    min-height: auto;
    padding: 34px;
  }

  .brand-panel::after {
    display: none;
  }

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

@media (max-width: 620px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    margin: -14px -14px 16px;
    padding: 18px 14px;
  }

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