/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:        #f8f9fa;
  --color-surface:   #ffffff;
  --color-border:    rgb(0, 0, 0, 0.25);
  --color-text:      #212529;
  --color-muted:     #6c757d;
  --color-primary:   rgb(140, 33, 43);
  --color-primary-h: rgb(210, 33, 43);
  --color-danger:    #fc3545;
  --color-success:   rgb(30, 107, 83);
  --color-warning:   #ffc107;
  --radius:          6px;
  --shadow:          0 1px 3px rgba(0,0,0,.1);
  --nav-height:      56px;
  --sidebar-width:   220px;
  --navbar-background: rgb(48, 48, 48);
  font-size: 14px;
  --color-unique:   rgba(0, 0, 0, 0.025);
  --graph-edge-bg:  var(--color-bg);
  --graph-edge-bg-h: var(--color-primary);
  --color-table-header-bg: rgba(0, 0, 0, 0.1);
  --color-table-header: rgba(0, 0, 0, 0.75);
}

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

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: monospace; background: var(--color-bg); padding: 1px 5px; border-radius: 3px; font-size: .9em; }
hr.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 2rem 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.text-muted { color: var(--color-muted); font-size: .875rem; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  height: var(--nav-height);
  background-color: var(--navbar-background);
  color: #fff;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand a { color: #fff; font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: .5rem; text-transform: uppercase; }
.navbar-logo { height: 48px; width: auto; display: block; }
.navbar-menu { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.navbar-link { color: rgba(255,255,255,.8); font-size: .875rem; }
.navbar-link:hover { color: #fff; text-decoration: none; }
.navbar-user-info { display: flex; align-items: center; gap: .75rem; border-left: 1px solid rgba(255,255,255,.2); padding-left: 1rem; }
.navbar-user { color: rgba(255,255,255,.7); font-size: .875rem; }
.navbar-link--signout { font-size: .8rem; }

/* Tenant switcher dropdown */
.navbar-dropdown { position: relative; }
.navbar-dropdown__trigger {
  display: flex; align-items: center; gap: .4rem;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: var(--radius); padding: .3rem .75rem;
  font-size: .875rem; cursor: pointer; white-space: nowrap;
}
.navbar-dropdown__trigger:hover { background: rgba(255,255,255,.2); }
.navbar-tenant-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.navbar-dropdown__caret { font-size: .65rem; opacity: .7; transition: transform .2s; }
.navbar-dropdown--open .navbar-dropdown__caret { transform: rotate(180deg); }
.navbar-dropdown__menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.15);
  list-style: none; min-width: 220px; z-index: 200; overflow: hidden;
}
.navbar-dropdown--open .navbar-dropdown__menu { display: block; }
.navbar-dropdown__item {
  width: 100%; text-align: left; padding: .55rem 1rem;
  background: none; border: none; cursor: pointer; font-size: .875rem;
  color: var(--color-text); display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.navbar-dropdown__item:hover { background: var(--color-bg); }
.navbar-dropdown__item--active { background: #eff6ff; font-weight: 600; }

/* Light navbar overrides */
.navbar--light .navbar-brand a { color: #111; }
.navbar--light .navbar-link { color: rgba(0,0,0,.65); }
.navbar--light .navbar-link:hover { color: #000; }
.navbar--light .navbar-user { color: rgba(0,0,0,.55); }
.navbar--light .navbar-user-info { border-left-color: rgba(0,0,0,.15); }
.navbar--light .navbar-dropdown__trigger { color: #111; }
.navbar--light .navbar-dropdown__trigger:hover { background: rgba(0,0,0,.08); }
.navbar--light .navbar-dropdown__caret { opacity: .5; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: calc(100vh - var(--nav-height)); }
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1rem;
  flex-shrink: 0;
}
.sidebar-tenant { margin-bottom: 1rem; }
.sidebar-tenant strong { display: block; font-size: .95rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: .25rem; }
.sidebar-link { display: block; padding: .4rem .5rem; border-radius: var(--radius); color: var(--color-text); font-size: .875rem; }
.sidebar-link:hover { background: var(--color-bg); text-decoration: none; }
.main-content { flex: 1; min-width: 0; padding: 1.5rem 2rem; }

/* ── Auth ────────────────────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg); background-image: url('/img/background.jpg'); background-position: bottom center; }
.auth-container { width: 100%; max-width: 400px; padding: 1rem; }
.auth-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.auth-logo { display: block; max-width: 180px; margin: 0 auto 1.25rem; }
.auth-title { font-size: 1.75rem; text-align: center; margin-bottom: .25rem; }
.auth-subtitle { text-align: center; color: var(--color-muted); margin-bottom: 1.5rem; }
.auth-message { margin-bottom: 1rem; color: var(--color-danger); }
.color-picker-row { display: flex; align-items: center; gap: .75rem; }
.color-picker-input { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius); cursor: pointer; background: none; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem;
  border-radius: var(--radius); border-width: 1px; border-style: solid; border-color: white black black white;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn--block { display: flex; width: 100%; justify-content: center; }
.btn--primary { background: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-h); text-decoration: none; }
.btn--secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn--secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn--danger { color: black; border-color: var(--color-border); }
.btn--danger:hover { background: var(--color-danger) !important; color: white; text-decoration: none; }
.btn--warning { background: var(--color-warning); color: #000; border-color: var(--color-warning); }
.btn--warning:hover { opacity: .9; color: #000; text-decoration: none; }
.btn--sm { padding: .25rem .6rem; font-size: .8rem; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form { max-width: 600px; }
.form--inline { max-width: 100%; }
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-weight: 500; margin-bottom: .3rem; font-size: .875rem; }
.form-label--checkbox { display: flex; align-items: center; gap: .4rem; font-weight: 400; cursor: pointer; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: .45rem .65rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  font-size: .875rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}
.form-input--error { border-color: var(--color-danger); }
.form-input--mono  { font-family: monospace; }
.form-textarea--code  { font-family: monospace; font-size: .8rem; }
.form-textarea--error { border-color: var(--color-danger); }
.form-error { display: block; color: var(--color-danger); font-size: .8rem; margin-top: .25rem; }
.form-hint { display: block; color: var(--color-muted); font-size: .78rem; margin-top: .25rem; }
.form-actions { display: flex; align-items: center; gap: .5rem; margin-top: 1.25rem; }
.form-select--inline { width: auto; padding: .2rem .4rem; }
.required-mark { color: var(--color-danger); margin-left: .2rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--color-border); text-align: left; }
.table th { background: var(--color-bg); font-weight: 600; }
.table tr:hover td { background: #f5f8ff; }
.table-actions { display: flex; gap: .4rem; white-space: nowrap; }
.table-empty { color: var(--color-muted); font-style: italic; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge, .role-badge, .field-type-badge {
  display: inline-flex; align-items: center;
  padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 500;
}
.badge--active { background: #d1fae5; color: #065f46; }
.api-key-reveal { background: #fefce8; border: 1px solid #fde047; border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.api-key-reveal__key { font-family: monospace; font-size: .9rem; word-break: break-all; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius); padding: .5rem .75rem; }
.badge--inactive { background: #fee2e2; color: #991b1b; }
.badge--warning { background: #fef3c7; color: #92400e; }
.role-badge--admin { background: #dbeafe; color: #1e40af; }
.role-badge--editor { background: #fef9c3; color: #854d0e; }
.role-badge--viewer { background: #f3f4f6; color: #374151; }
.field-type-badge--text { background: #e0e7ff; color: #3730a3; }
.field-type-badge--number,
.field-type-badge--percent { background: #d1fae5; color: #065f46; }
.field-type-badge--amount { background: #e1daf5; color: #065f46; }
.field-type-badge--date { background: #fce7f3; color: #9d174d; }
.field-type-badge--boolean { background: #fef3c7; color: #92400e; }
.field-type-badge--enum { background: #ede9fe; color: #5b21b6; }
.field-type-badge--reference { background: #f0fdf4; color: #166534; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; }
.alert--success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--color-success); }
.alert--error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--color-danger); }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .5rem; }
.page-header h1 { margin: 0; }
.page-header__actions { display: flex; gap: .5rem; }

/* ── Cards / Grids ───────────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.entity-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
  transition: box-shadow .15s, border-color .15s;
  text-decoration: none; color: var(--color-text);
}
.entity-card:hover { box-shadow: var(--shadow); border-color: var(--color-primary); text-decoration: none; }
.entity-card__icon { font-size: 1.5rem; }
.entity-card__name { font-weight: 600; }
.entity-card__desc { font-size: .8rem; color: var(--color-muted); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-grid { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem 2rem; text-align: center; min-width: 140px; }
.stat-card__value { font-size: 2.5rem; font-weight: 700; }
.stat-card__label { color: var(--color-muted); }
.stat-card__link { display: inline-block; margin-top: .5rem; }

/* ── Detail List ─────────────────────────────────────────────────────────── */
.detail-list { display: grid; grid-template-columns: 200px 1fr; gap: .5rem 1rem; margin-bottom: 1.5rem; }
.detail-list__label { font-weight: 500; color: var(--color-muted); align-self: start; }
.detail-list__value { }

/* ── Tenant Picker ───────────────────────────────────────────────────────── */
.tenant-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.tenant-list__btn {
  width: 100%; text-align: left; padding: .75rem 1rem;
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  transition: background .15s;
}
.tenant-list__btn:hover { background: #e9ecef; }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Entity graph ────────────────────────────────────────────────────────── */
#entity-graph { width: 100%; height: calc(100vh - var(--nav-height) - 80px); min-height: 400px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; font-size: .875rem; }
.pagination-info { color: var(--color-muted); }
.pagination-link { }

/* ── Record Grid ─────────────────────────────────────────────────────────── */
.grid-wrap { overflow: auto; max-height: calc(100vh - var(--nav-height) - 7rem); border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
.record-grid { border-collapse: collapse; width: max-content; min-width: 100%; font-size: .875rem; }
.grid-th {
  background: var(--color-table-header-bg); color: var(--color-table-header); padding: .45rem .75rem;
  text-align: left; font-weight: 600; white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
}
.grid-th--id  { width: 52px; text-align: right; }
.grid-th--del { width: 36px; }
.grid-th__required { color: var(--color-danger); margin-left: .2em; font-weight: bold; }
.grid-cell {
  padding: .35rem .75rem; border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  vertical-align: middle; max-width: 320px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 100px;
}
.grid-cell[data-type="boolean"] { text-align: center; }
.grid-cell[data-type="number"],
.grid-cell[data-type="percent"],
.grid-cell[data-type="amount"] { text-align:right; }
.grid-cell.is-unique { background-color: var(--color-unique); font-weight: bold; }
.grid-cell:last-child { border-right: none; }
.grid-cell[tabindex]:hover { background: #f0f7ff; cursor: cell; }
.grid-cell[tabindex]:focus { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.grid-cell--active { padding: 0; overflow: visible; background: #fff; outline: 2px solid var(--color-primary); outline-offset: -2px; }
.grid-cell--id  { color: var(--color-muted); font-size: .8rem; text-align: right; width: 52px; min-width: unset; }
.grid-id-link   { color: inherit; text-decoration: none; }
.grid-id-link:hover { text-decoration: underline; }
.grid-cell--del { width: 40px; padding: .2rem .3rem; text-align: center; min-width: unset; }
.grid-cell--del .btn { font-size: 1rem; line-height: 1; padding: .2rem .45rem; background-color: rgb(128, 128, 128, 0.1); }
.grid-cell--error,
.grid-cell--required-empty { background: #fff5f5 !important; outline: 1px solid var(--color-danger) !important; }
.grid-row--dirty .grid-cell--id::after { content: '•'; color: var(--color-warning); margin-left: 3px; }
.grid-row--saving { opacity: .55; pointer-events: none; }
.grid-row--error .grid-cell--id { color: var(--color-danger); }
.grid-input {
  width: 100%; height: 100%; border: none; outline: none;
  padding: .35rem .75rem; background: transparent;
  font-size: inherit; font-family: inherit; display: block;
}
input[type="checkbox"].grid-input { width: auto; padding: 0; margin: .3rem auto; display: block; cursor: pointer; }
input[type="date"].grid-input, input[type="number"].grid-input { padding: .3rem .5rem; }
select.grid-input { padding: .3rem .5rem; }
.grid-input-amount { display: flex; width: 100%; height: 100%; }
.grid-input--currency { width: 3.8em; min-width: 3.8em; padding: .35rem .4rem; border-right: 1px solid var(--color-border); flex-shrink: 0; font-family: monospace; text-transform: uppercase; }
.grid-input--amount  { flex: 1; min-width: 0; }

/* Amount compound input in forms */
.amount-input-group { display: flex; gap: .5rem; align-items: center; }
.form-input--currency { width: 5rem; flex-shrink: 0; font-family: monospace; text-transform: uppercase; }
.form-input--amount  { flex: 1; }

/* ── Delete confirmation modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  max-width: 560px; width: 100%;
  display: flex; flex-direction: column;
  max-height: 90vh; overflow-y: auto;
}
.modal__header {
  padding: 1.25rem 1.5rem .75rem;
  border-bottom: 1px solid var(--color-border);
}
.modal__title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.modal__body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .75rem; }
.modal__intro { margin: 0; }
.modal__dep-list {
  margin: 0; padding-left: 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .875rem; color: var(--color-text);
}
.modal__warn {
  margin: 0; font-weight: 600;
  color: var(--color-danger); font-size: .875rem;
}
.modal__footer {
  padding: 1rem 1.5rem 1.5rem;
  display: flex; flex-direction: column; gap: .75rem;
}
.modal__option { display: flex; flex-direction: column; gap: .25rem; }
.modal__option .btn { align-self: flex-start; text-align: left; white-space: normal; }
.modal__option-desc { font-size: .8rem; color: var(--color-muted); padding-left: .1rem; }

/* ── Record History ──────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 1.25rem; }
.history-snapshot { border: 1px solid var(--color-border); border-radius: 6px; overflow: hidden; }
.history-snapshot__header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: .5rem .75rem; background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border); gap: 1rem;
}
.history-snapshot__ts   { font-size: .8rem; color: var(--color-muted); font-family: monospace; }
.history-snapshot__user { font-size: .85rem; font-weight: 600; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table__field {
  padding: .35rem .75rem; font-weight: 500; font-size: .85rem;
  color: var(--color-muted); white-space: nowrap; width: 30%;
  border-bottom: 1px solid var(--color-border);
}
.history-table__value {
  padding: .35rem .75rem; font-size: .9rem;
  border-bottom: 1px solid var(--color-border);
}
.history-table tr:last-child th,
.history-table tr:last-child td { border-bottom: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { padding: 1rem; }
  .detail-list { grid-template-columns: 1fr; }
}
