:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-subdued: #f1f2f4;
  --text: #202223;
  --muted: #6d7175;
  --border: #dfe3e8;
  --primary: #008060;
  --primary-dark: #006e52;
  --danger: #d72c0d;
  --warning: #b98900;
  --success: #008060;
  --shadow: 0 1px 0 rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #101418;
  color: #fff;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark,
.login-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #00a47c;
  color: white;
  font-weight: 800;
}

.brand-title {
  font-weight: 800;
  letter-spacing: .04em;
}

.brand-subtitle,
.sidebar-footer {
  color: #b8c0c8;
  font-size: 13px;
}

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

.nav-item {
  border: 0;
  background: transparent;
  color: #d8dee4;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #00a47c;
  border-radius: 999px;
}

.main {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar p,
.card p,
.muted {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

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

.card-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

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

.stat-card {
  display: grid;
  gap: 8px;
}

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

.stat-card strong {
  font-size: 30px;
}

.login-wrap {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(440px, 100%);
}

.login-card h2 {
  margin-bottom: 6px;
}

.form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
}

input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,128,96,.14);
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

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

.btn-danger:hover {
  filter: brightness(.92);
}

.btn-small {
  padding: 7px 10px;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

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

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

code {
  background: #f1f2f4;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 6px;
}

.badge {
  display: inline-flex;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #eef1f5;
  color: #4b5563;
}

.badge-success {
  background: #e3f1df;
  color: var(--success);
}

.badge-warning {
  background: #fff4d8;
  color: var(--warning);
}

.badge-danger {
  background: #fde8e3;
  color: var(--danger);
}

.error {
  color: var(--danger);
  background: #fde8e3;
  border: 1px solid #f5c6bc;
  border-radius: 10px;
  padding: 10px 12px;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: static;
  }

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

  .topbar {
    flex-direction: column;
  }
}

/* Login standalone */
.is-logged-out .app-shell {
  grid-template-columns: 1fr;
}

.is-logged-out .sidebar,
.is-logged-out .topbar {
  display: none;
}

.is-logged-out .main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.is-logged-out .login-wrap {
  width: min(440px, 100%);
  min-height: auto;
}

.is-logged-out .login-card {
  width: 100%;
}

.is-logged-in .main {
  display: block;
}


/* Operational tables */
.table-total {
  padding: 12px 14px 2px;
  color: var(--muted);
  font-size: 14px;
}

.soft-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: #f7f8fa;
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: #111827;
  border-radius: 8px;
  min-width: 34px;
  min-height: 32px;
  padding: 6px 8px;
  font-weight: 800;
  cursor: pointer;
}

.icon-btn:hover {
  background: #f7f8fa;
}

.icon-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.icon-btn-blue {
  border-color: #b8cdfd;
  color: #155dfc;
}

.icon-btn-green {
  border-color: #bfe3c1;
  color: #108043;
}

.icon-btn-red {
  border-color: #ffc2bd;
  color: #d72c0d;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(17, 24, 39, .42);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(760px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
}

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

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.modal-header h2 {
  margin: 0;
}

.modal-body {
  padding: 20px;
}

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

.detail-grid div {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fafbfc;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 5px;
}

.detail-grid strong {
  word-break: break-word;
}

.detail-subtitle {
  margin: 20px 0 10px;
}

.payload-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #f9fafb;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
}

/* Responsive tables */
@media (max-width: 980px) {
  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 860px;
  }
}

@media (max-width: 720px) {
  .card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .card-header .btn {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody tr {
    border: 1px solid var(--border);
    border-radius: 14px;
    margin: 12px;
    padding: 6px 0;
    background: #fff;
  }

  tbody tr td {
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 11px 14px;
    text-align: right;
  }

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

  tbody tr td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
  }

  .row-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

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

  .modal {
    max-height: 90vh;
  }
}


.action-btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  background: #fff;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.action-btn-primary {
  border-color: #b8cdfd;
  background: #eef4ff;
  color: #155dfc;
}

.action-btn-primary:hover:not(:disabled) {
  background: #e0ebff;
}

.action-btn-danger {
  border-color: #ffc2bd;
  background: #fff1ef;
  color: #d72c0d;
}

.action-btn-danger:hover:not(:disabled) {
  background: #ffe4e0;
}

@media (max-width: 720px) {
  .action-btn {
    flex: 1;
    min-width: 110px;
  }
}


.action-icon {
  font-size: 14px;
  line-height: 1;
}

.action-label {
  line-height: 1;
}

@media (max-width: 460px) {
  .action-btn {
    min-width: 44px;
    padding: 8px 10px;
  }

  .action-label {
    display: none;
  }
}


/* Prevent auth/layout flash before session hydration */
.auth-loading .app-shell {
  visibility: hidden;
}

.auth-loading {
  background: var(--bg);
}

.assign-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.form-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

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

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.required {
  color: var(--danger);
}

.field-control {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.field-control:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--primary);
}

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

.form-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}



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

