*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
}

a {
  color: var(--action);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--header-h);
  background: var(--nav);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
}

.app-header a {
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
}

.app-brand {
  font-weight: 650;
  font-size: 16px;
  color: #fff !important;
  margin-right: var(--space-3);
  white-space: nowrap;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.app-nav a.is-active,
.app-nav a[aria-current="page"] {
  background: var(--nav-active);
  box-shadow: inset 3px 0 0 var(--nav-indicator);
  color: #fff;
}

.app-nav-right {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.app-main {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: var(--space-5) var(--space-6);
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-header h1,
.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.5px;
  line-height: 1.25;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-surface);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4);
  border-radius: 7px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none !important;
}

.btn-primary,
.btn-info,
.btn-success {
  background: var(--action);
  color: #fff !important;
}
.btn-primary:hover,
.btn-info:hover,
.btn-success:hover {
  background: var(--action-hover);
}

.btn-secondary,
.btn-default {
  background: var(--surface);
  border-color: var(--divider);
  color: var(--text) !important;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: #f0c9c4;
  color: var(--danger-text) !important;
}

.btn-warning {
  background: var(--warning-bg);
  border-color: #f0d9a8;
  color: var(--warning-text) !important;
}

.btn-xs,
.btn-sm {
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.form-control,
select.form-control,
textarea.form-control,
input.form-control {
  min-height: 40px;
  width: 100%;
  max-width: 100%;
  padding: 0 var(--space-3);
  border: 1px solid var(--divider);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea.form-control {
  min-height: 96px;
  padding: var(--space-3);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-group label,
.field-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
  font-size: 14px;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.form-inline .form-control {
  width: auto;
  min-width: 140px;
}

.checkbox label {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  color: var(--text-muted);
}

.table-toolbar {
  margin: 0 0 var(--space-3);
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - var(--header-h) - 180px);
  width: 100%;
  border: 1px solid var(--divider);
  border-radius: var(--radius-md);
  background: var(--surface);
}

table.data-table,
table.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
}

table.data-table th,
table.data-table td,
table.table th,
table.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  text-align: left;
  vertical-align: top;
}

/* Short values stay compact; long cells wrap instead of stretching the table. */
table.data-table td,
table.table td {
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 16rem;
}

table.data-table thead th,
table.table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
  background: #fafbfd;
  vertical-align: bottom;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 9.5rem;
  box-shadow: inset 0 -1px 0 var(--divider);
}

th.th-filterable {
  min-width: 6.5rem;
  max-width: 9.5rem;
  vertical-align: bottom;
}

th.col-actions {
  max-width: none;
  min-width: 7rem;
  width: 1%;
  white-space: nowrap;
}

button.th-sort {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  min-height: 2.6em;
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.th-sort-label {
  flex: 1;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

button.th-sort:hover {
  color: var(--action);
}

.th-sort-ind {
  flex: 0 0 auto;
  color: var(--action);
  font-size: 11px;
  line-height: 1.3;
}

th.is-sorted-asc,
th.is-sorted-desc {
  color: var(--text);
}

.th-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 32px;
}

button.th-clear-all {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

button.th-clear-all:hover {
  color: var(--danger-text);
  border-color: #f0c9c4;
  background: var(--danger-bg);
}

input.th-filter {
  min-height: 32px !important;
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 400;
}

table.data-table tbody tr:hover,
table.table tbody tr:hover {
  background: #f8fafc;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 650;
}

.chip-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.chip-error,
.chip-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.chip-neutral {
  background: #eef1f6;
  color: var(--text-muted);
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--divider);
  margin-bottom: var(--space-4);
}

.alert-danger,
.alert-error {
  background: var(--danger-bg);
  border-color: #f0c9c4;
  color: var(--danger-text);
}

.alert-success {
  background: var(--success-bg);
  border-color: #cfe8dc;
  color: var(--success-text);
}

.alert-info,
.alert-warning {
  background: var(--warning-bg);
  border-color: #f0d9a8;
  color: var(--warning-text);
}

.empty-state {
  padding: var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background:
    radial-gradient(circle at top, #e8eefc 0%, transparent 55%),
    linear-gradient(180deg, #edf2fb 0%, var(--canvas) 100%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-overlay);
  padding: 40px;
  position: relative;
}

.auth-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: linear-gradient(90deg, var(--nav), var(--action));
}

.auth-card h1 {
  margin: 0 0 var(--space-2);
  font-size: 24px;
  font-weight: 650;
}

.auth-card .auth-brand {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.auth-card .form-control,
.auth-card .btn {
  min-height: 48px;
}

.auth-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.pager {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
}

.row.danger,
tr.danger {
  background: var(--danger-bg);
}

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

.text-center {
  text-align: center;
}

.navbar,
.navbar-inverse,
.navbar-default {
  display: none;
}

@media (max-width: 700px) {
  .app-main {
    padding: var(--space-4);
  }
  .auth-card {
    padding: 32px 21px 24px;
    border-radius: 16px;
  }
  .page-header h1,
  .page-title {
    font-size: 24px;
  }
}
