:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #dde2e8;
  --color-text: #1c2530;
  --color-text-muted: #5b6673;
  --color-primary: #2b5adf;
  --color-primary-hover: #1f45b3;
  --color-primary-contrast: #ffffff;
  --color-danger: #c0362c;
  --color-danger-bg: #fbeae9;
  --color-success: #1b7a43;
  --color-success-bg: #e8f6ee;
  --color-warning-bg: #fff6e0;
  --color-warning-text: #8a6100;
  --sidebar-width: 232px;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-size: 15px;
}

* {
  box-sizing: border-box;
}

/* .btn and other component classes set `display` unconditionally, which otherwise beats the
   browser's default [hidden] rule at equal specificity since author CSS always wins over the
   user-agent stylesheet. Without this, toggling the `hidden` property/attribute via JS has no
   visual effect on elements carrying such classes (e.g. role-gated nav links and buttons). */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #16233d;
  color: #cbd5e6;
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar__brand {
  padding: 0 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0.75rem;
}

.sidebar__org {
  padding: 0 1.25rem 0.75rem;
  font-size: 0.8rem;
  color: #90a0ba;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav a {
  color: #cbd5e6;
  padding: 0.55rem 1.25rem;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.1);
  border-left-color: var(--color-primary);
  color: #ffffff;
  font-weight: 600;
}

.sidebar__footer {
  margin-top: auto;
  padding: 0.75rem 1.25rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar__title {
  font-size: 1.05rem;
  font-weight: 600;
}

.topbar__user {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.content {
  padding: 1.5rem;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  border-color: #b7c0cc;
}

.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 600;
}

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

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

.btn-danger:hover {
  background: var(--color-danger-bg);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}

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

.form-field {
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--color-text);
}

.form-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.8rem;
  margin-top: 0.3rem;
}

.field-error:empty {
  display: none;
}

input.has-error, select.has-error, textarea.has-error {
  border-color: var(--color-danger);
}

.alert {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(192, 54, 44, 0.25);
}

.alert-info {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border: 1px solid rgba(138, 97, 0, 0.2);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: #fafbfc;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.table-wrapper table {
  border: none;
}

.table-wrapper .table-wrapper table th:first-child,
.table-wrapper table th:first-child,
.table-wrapper table td:first-child {
  padding-left: 1rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-draft { background: #eef0f3; color: #4a5462; }
.badge-active { background: var(--color-success-bg); color: var(--color-success); }
.badge-expired { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-terminated { background: var(--color-danger-bg); color: var(--color-danger); }

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}

.empty-state h3 {
  color: var(--color-text);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar input[type="search"] {
  min-width: 220px;
}

.toolbar select {
  width: auto;
}

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #eef1f6;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.chip__remove {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.chip__remove:hover {
  color: var(--color-danger);
}

.section {
  margin-bottom: 1.75rem;
}

.section__title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--color-border);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  z-index: 100;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  padding: 1.25rem;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal__close {
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.tabs button {
  border: none;
  background: none;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  font-family: inherit;
}

.tabs button.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

.picker-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

.picker-item {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  font-size: 0.88rem;
}

.picker-item:last-child {
  border-bottom: none;
}

.picker-item:hover {
  background: #f2f5fa;
}

.picker-item small {
  color: var(--color-text-muted);
  display: block;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}

.toast {
  background: var(--color-text);
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  box-shadow: var(--shadow-sm);
  max-width: 320px;
}

.toast-error {
  background: var(--color-danger);
}

.toast-success {
  background: var(--color-success);
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin-bottom: 1.25rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.text-muted {
  color: var(--color-text-muted);
}

.mt-1 { margin-top: 0.75rem; }
.mt-2 { margin-top: 1.5rem; }

@media (max-width: 820px) {
  .sidebar {
    display: none;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}
