@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/Inter.woff2") format("woff2");
}

:root {
  --bg:            #f4f4f5;
  --surface:       #ffffff;
  --surface-2:     #f0f0f0;
  --border:        #e4e4e7;
  --text:          #111827;
  --text-muted:    #6b7280;
  --accent:        #ff6820;
  --accent-text:   #ffffff;
  --accent-soft:   rgba(255, 104, 32, 0.12);
  --success:       #22c55e;
  --success-soft:  rgba(34, 197, 94, 0.12);
  --info:          #60a5fa;
  --info-soft:     rgba(96, 165, 250, 0.12);
  --danger:        #ef4444;
  --danger-soft:   rgba(239, 68, 68, 0.12);
  --shadow:        0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius:        12px;
  --radius-lg:     16px;
  --radius-sm:     10px;
}

:root[data-theme="dark"] {
  --bg:            #0d0d0d;
  --surface:       #181818;
  --surface-2:     #222222;
  --border:        #2a2a2a;
  --text:          #ffffff;
  --text-muted:    #9ca3af;
  --accent:        #ff6820;
  --accent-text:   #ffffff;
  --accent-soft:   rgba(255, 104, 32, 0.18);
  --success:       #22c55e;
  --success-soft:  rgba(34, 197, 94, 0.16);
  --info:          #60a5fa;
  --info-soft:     rgba(96, 165, 250, 0.16);
  --danger:        #ef4444;
  --danger-soft:   rgba(239, 68, 68, 0.16);
  --shadow:        0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d0d0d;
    --surface:       #181818;
    --surface-2:     #222222;
    --border:        #2a2a2a;
    --text:          #ffffff;
    --text-muted:    #9ca3af;
    --accent:        #ff6820;
    --accent-text:   #ffffff;
    --accent-soft:   rgba(255, 104, 32, 0.18);
    --success:       #22c55e;
    --success-soft:  rgba(34, 197, 94, 0.16);
    --info:          #60a5fa;
    --info-soft:     rgba(96, 165, 250, 0.16);
    --danger:        #ef4444;
    --danger-soft:   rgba(239, 68, 68, 0.16);
    --shadow:        0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background 0.15s ease, color 0.15s ease;
}

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

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  transition: width 0.15s ease;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-collapse {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease;
}

.sidebar-collapse svg {
  opacity: 1;
  transition: opacity 0.15s ease, display 0.15s allow-discrete;
}

@starting-style {
  .sidebar-collapse svg { opacity: 0; }
}

.sidebar-collapse:not(.collapsed):hover { color: var(--text); border-color: var(--accent); }

.nav-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 4px 12px 8px;
  white-space: nowrap;
  overflow: hidden;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.nav-item svg { flex-shrink: 0; }

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  margin-left: -12px;
  margin-right: -12px;
  padding: 12px 12px 0;
}

.account {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
}

.account-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.account-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-role {
  font-size: 11.5px;
  color: var(--text-muted);
}

.account svg { flex-shrink: 0; color: var(--text-muted); }

/* Sidebar collapsed state */
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .account-info,
.sidebar.collapsed .account svg { display: none; }
.sidebar.collapsed .nav-item,
.sidebar.collapsed .account { justify-content: center; }
.sidebar.collapsed .sidebar-collapse svg { display: none; opacity: 0; }
.sidebar.collapsed .sidebar-collapse { border-color: transparent; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
}

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

.theme-toggle {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

.content {
  padding: 28px;
  flex: 1;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
}

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

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
}

.page-header p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  min-width: 220px;
}

.search-input input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  width: 100%;
  font-family: inherit;
}

.filter-wrap { position: relative; }

.filter-btn { color: var(--text); }

.filter-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 20;
}

.filter-menu[hidden] { display: none; }

.filter-menu button {
  text-align: left;
  padding: 7px 9px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.filter-menu button:hover { background: var(--surface-2); }

.filter-menu button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary:hover { filter: brightness(1.08); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

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

.confirm-message {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: var(--surface-2); }

.btn[hidden] { display: none; }
.btn:disabled { opacity: 0.4; cursor: default; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.icon-btn.accent:hover { background: var(--accent-soft); color: var(--accent); }

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

.action-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Table */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  table-layout: fixed;
}

thead th {
  text-align: left;
  padding: 10px 22px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody td {
  padding: 13px 22px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

tbody tr:hover { background: var(--surface-2); }

.col-actions { width: 44px; }

.cell-primary {
  font-weight: 600;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.cell-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cell-location,
.cell-users-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  min-width: 0;
}

.cell-location svg,
.cell-users-count svg {
  flex-shrink: 0;
}

.cell-location-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-square { border-radius: var(--radius-sm); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-success .badge-dot { background: var(--success); }

.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-danger .badge-dot { background: var(--danger); }

.badge-role {
  display: inline-flex;
  font-weight: 600;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-role--admin { background: var(--accent-soft); color: var(--accent); }
.badge-role--operator { background: var(--info-soft); color: var(--info); }
.badge-role--viewer { background: var(--success-soft); color: var(--success); }

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 22px;
  white-space: normal;
}

/* Table footer / pagination */
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.table-count {
  font-size: 13px;
  color: var(--text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn {
  min-width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.page-btn:hover:not(:disabled) { background: var(--surface-2); }

.page-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.page-btn:disabled { opacity: 0.4; cursor: default; }

.per-page-select {
  margin-left: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

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

.modal-header h3 { margin: 0; font-size: 15px; }

.modal-body {
  padding: 18px;
}

.modal-body > form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select {
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-prefixed {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}

.field-prefixed:focus-within {
  border-color: var(--accent);
}

.field-prefix-badge {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13.5px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.field-prefixed input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
}

.field-prefixed input:focus {
  outline: none;
}

.field-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}

.detail-list > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-list dt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
}

.detail-list dd {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

@media (max-width: 720px) {
  .sidebar:not(.collapsed) {
    width: 72px;
  }
  .sidebar:not(.collapsed) .brand-name,
  .sidebar:not(.collapsed) .nav-section-label,
  .sidebar:not(.collapsed) .nav-item span,
  .sidebar:not(.collapsed) .account-info,
  .sidebar:not(.collapsed) .account svg {
    display: none;
  }
  .sidebar:not(.collapsed) .nav-item,
  .sidebar:not(.collapsed) .account {
    justify-content: center;
  }
  .content { padding: 16px; }
  .page-header { flex-wrap: wrap; }
  .search-input { flex: 1 1 100%; min-width: 0; }
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login-brand-mark {
  width: 40px;
  height: 40px;
}

.login-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.login-subtitle {
  margin: -8px 0 6px;
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: center;
}

.login-card .field {
  width: 100%;
}

.login-error {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.login-info {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--info-soft);
  color: var(--info);
  font-size: 13px;
  text-align: center;
}

.login-submit {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

.login-footer {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.login-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.login-footer a:hover { text-decoration: underline; }
