:root {
  --green: #3c544c;
  --green-dark: #2f433c;
  --green-soft: #e8efec;
  --cream: #f6f4ee;
  --surface: #ffffff;
  --ink: #20302b;
  --muted: #66756f;
  --line: #dbe3df;
  --gold: #d4a84f;
  --danger: #a33e3e;
  --danger-soft: #fae9e7;
  --warning: #94631c;
  --warning-soft: #fff3d9;
  --success: #2e6b4d;
  --success-soft: #e4f2e9;
  --shadow: 0 18px 50px rgba(37, 56, 49, 0.1);
  --radius: 18px;
  --sidebar: 270px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.login-page {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.1fr);
}
.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(34px, 6vw, 84px);
  overflow: hidden;
  color: white;
  background: var(--green);
}
.login-brand::after {
  position: absolute;
  right: -140px;
  bottom: -160px;
  width: 450px;
  height: 450px;
  content: "";
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 50%;
  box-shadow: 0 0 0 55px rgba(255,255,255,.035), 0 0 0 110px rgba(255,255,255,.025);
}
.login-brand img { position: relative; z-index: 1; width: min(320px, 78%); filter: brightness(0) invert(1); }
.login-brand-copy { position: relative; z-index: 1; max-width: 520px; }
.login-brand-copy .eyebrow { color: #dfeae5; }
.login-brand-copy h1 { margin: 10px 0 18px; font-family: Georgia, serif; font-size: clamp(38px, 5vw, 68px); line-height: 1; }
.login-brand-copy p { max-width: 44ch; margin: 0; color: #e7efec; font-size: 18px; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(460px, 100%); padding: clamp(28px, 5vw, 48px); border: 1px solid var(--line); border-radius: 26px; background: var(--surface); box-shadow: var(--shadow); }
.login-card h2 { margin: 6px 0 8px; font-size: 30px; }
.login-card > p { margin: 0 0 26px; color: var(--muted); }
.build-badge { display: inline-flex; padding: 5px 10px; border-radius: 99px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }

.app-shell { display: grid; min-height: 100vh; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 28px 20px 22px;
  color: white;
  background: var(--green);
}
.sidebar-logo { width: 185px; max-height: 74px; object-fit: contain; filter: brightness(0) invert(1); }
.sidebar-module { margin: 12px 0 0; color: #d9e6e1; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { display: grid; gap: 7px; margin-top: 38px; }
.sidebar-nav a { display: flex; align-items: center; gap: 11px; padding: 12px 14px; border-radius: 12px; color: #e7efec; text-decoration: none; font-weight: 650; }
.sidebar-nav a:hover, .sidebar-nav a.active { color: white; background: rgba(255,255,255,.12); }
.sidebar-footer { margin-top: auto; padding-top: 24px; border-top: 1px solid rgba(255,255,255,.17); }
.sidebar-footer strong, .sidebar-footer span { display: block; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer span { margin-top: 4px; color: #d9e6e1; font-size: 12px; }
.sidebar-footer .btn { margin-top: 14px; }
.main { min-width: 0; padding: clamp(24px, 4vw, 48px); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-header h1 { margin: 4px 0 5px; font-family: Georgia, serif; font-size: clamp(30px, 4vw, 44px); line-height: 1.08; }
.page-header p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--green); font-size: 12px; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; }

.btn { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 9px 15px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; text-decoration: none; font-weight: 750; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: wait; opacity: .6; transform: none; }
.btn-primary { color: white; background: var(--green); }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { color: var(--green); border-color: var(--green); background: white; }
.btn-ghost { color: inherit; border-color: var(--line); background: transparent; }
.btn-danger { color: white; background: var(--danger); }
.btn-sm { min-height: 34px; padding: 6px 10px; border-radius: 9px; font-size: 13px; }
.btn-block { width: 100%; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 750; }
.field small { color: var(--muted); }
input, select, textarea { width: 100%; min-height: 43px; padding: 9px 11px; color: var(--ink); border: 1px solid #cfd9d4; border-radius: 10px; outline: none; background: white; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(60,84,76,.12); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-span-2 { grid-column: span 2; }
.form-span-3 { grid-column: span 3; }
.form-section { margin: 28px 0 14px; padding-top: 22px; border-top: 1px solid var(--line); }
.form-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.form-section h3 { margin: 0 0 5px; font-size: 18px; }
.form-section p { margin: 0 0 17px; color: var(--muted); font-size: 13px; }
.check-card { display: flex; min-height: 72px; align-items: flex-start; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfb; }
.check-card input { width: 18px; min-height: 18px; margin-top: 2px; accent-color: var(--green); }
.check-card strong, .check-card span { display: block; }
.check-card span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.check-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

.metric-grid { display: grid; gap: 15px; margin-bottom: 26px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(37,56,49,.05); }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 650; }
.metric-card strong { display: block; margin-top: 9px; font-family: Georgia, serif; font-size: 34px; line-height: 1; }
.metric-card small { display: block; margin-top: 8px; color: var(--muted); }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(37,56,49,.045); }
.panel + .panel { margin-top: 20px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.panel-header h2, .panel-header h3 { margin: 0; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel-body { padding: 22px; }
.filter-row { display: grid; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); grid-template-columns: minmax(220px, 1fr) 190px 190px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; border-bottom: 1px solid #edf1ef; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #fafbf9; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
tbody tr[data-href] { cursor: pointer; }
tbody tr[data-href]:hover { background: #f7faf8; }
tbody tr:last-child td { border-bottom: 0; }
.institution-cell strong, .institution-cell span { display: block; }
.institution-cell span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.module-dots { display: flex; flex-wrap: wrap; gap: 5px; }
.module-dot { padding: 4px 7px; border-radius: 99px; color: #76817d; background: #edf0ef; font-size: 10px; font-weight: 800; }
.module-dot.on { color: var(--green-dark); background: var(--green-soft); }
.progress { width: 130px; height: 7px; overflow: hidden; border-radius: 99px; background: #e8edeb; }
.progress span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.usage-text { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 99px; font-size: 11px; font-weight: 850; }
.badge::before { width: 6px; height: 6px; content: ""; border-radius: 50%; background: currentColor; }
.status-active { color: var(--success); background: var(--success-soft); }
.status-trial { color: #4767a0; background: #e8eef9; }
.status-past_due { color: var(--warning); background: var(--warning-soft); }
.status-suspended, .status-cancelled { color: var(--danger); background: var(--danger-soft); }
.status-inactive { color: #68726e; background: #ecefed; }

.detail-layout { display: grid; align-items: start; gap: 22px; grid-template-columns: minmax(0, 1.55fr) minmax(290px, .65fr); }
.detail-stack { display: grid; gap: 20px; }
.summary-list { display: grid; gap: 13px; }
.summary-row { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 12px; border-bottom: 1px solid #edf1ef; }
.summary-row:last-child { padding-bottom: 0; border-bottom: 0; }
.summary-row span { color: var(--muted); }
.summary-row strong { text-align: right; }
.item-list { display: grid; gap: 10px; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; }
.item strong, .item span { display: block; }
.item span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.item-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.empty { padding: 28px; color: var(--muted); text-align: center; border: 1px dashed #ccd7d2; border-radius: 12px; background: #fbfcfb; }
.danger-zone { border-color: #efc7c3; }
.danger-zone .panel-header { border-color: #efdedb; }
.danger-zone h3 { color: var(--danger); }
.notice { padding: 13px 15px; border-radius: 11px; font-size: 13px; }
.notice-info { color: var(--green-dark); background: var(--green-soft); }
.notice-warning { color: var(--warning); background: var(--warning-soft); }

.audit-list { display: grid; gap: 0; }
.audit-entry { display: grid; gap: 4px; padding: 13px 0; border-bottom: 1px solid #edf1ef; }
.audit-entry:last-child { border-bottom: 0; }
.audit-entry strong { font-size: 13px; }
.audit-entry span { color: var(--muted); font-size: 12px; }

.modal-overlay { position: fixed; z-index: 100; inset: 0; display: none; place-items: center; padding: 22px; overflow-y: auto; background: rgba(24,38,33,.58); backdrop-filter: blur(3px); }
.modal-overlay.open { display: grid; }
.modal { width: min(620px, 100%); max-height: calc(100vh - 44px); overflow-y: auto; padding: 26px; border-radius: 20px; background: white; box-shadow: 0 30px 100px rgba(0,0,0,.25); }
.modal-lg { width: min(920px, 100%); }
.modal-xl { width: min(1100px, 100%); }
.modal h2 { margin: 0 0 5px; }
.modal-intro { margin: 0 0 22px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }

.toast-region { position: fixed; z-index: 200; right: 24px; bottom: 24px; display: grid; gap: 10px; width: min(390px, calc(100vw - 48px)); }
.toast { padding: 14px 16px; color: white; border-radius: 12px; background: var(--green); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.loading { min-height: 180px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid #dce5e1; border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
  :root { --sidebar: 220px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .detail-layout { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-span-3 { grid-column: span 2; }
}
@media (max-width: 760px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { min-height: 300px; padding: 34px; }
  .login-brand img { width: 210px; }
  .login-brand-copy h1 { font-size: 40px; }
  .login-panel { padding: 18px; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 17px 18px; }
  .sidebar-logo { width: 145px; max-height: 52px; }
  .sidebar-module { margin-top: 4px; }
  .sidebar-nav { display: flex; margin-top: 18px; overflow-x: auto; }
  .sidebar-nav a { flex: 0 0 auto; padding: 9px 11px; font-size: 13px; }
  .sidebar-footer { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 14px; }
  .sidebar-footer > div { min-width: 0; flex: 1; }
  .sidebar-footer .btn { width: auto; margin: 0; }
  .main { padding: 22px 16px 40px; }
  .page-header { align-items: stretch; flex-direction: column; }
  .metric-grid, .form-grid, .form-grid-3, .check-grid { grid-template-columns: 1fr; }
  .form-span-2, .form-span-3 { grid-column: auto; }
  .filter-row { grid-template-columns: 1fr; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .modal { padding: 20px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}
