:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --success-bg: #ecfdf3;
  --warning-bg: #fff7ed;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark mode: applied via [data-theme="dark"] on <html>, toggled per-device
   from the topbar and remembered in that browser's localStorage. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --border: #2a2e37;
  --text: #e7e9ee;
  --text-muted: #9aa1ac;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --danger: #f87171;
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --warning-bg: rgba(251, 146, 60, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

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

/* Organization logo: always shown at 50x50 px (standard web resolution). */
.org-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

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

.user-badge {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.app {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 16px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.hidden { display: none !important; }

/* ---------- Cards / Forms ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

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

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.notes-input {
  width: 100%;
  min-width: 160px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}
.notes-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}
.notes-readonly {
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-wrap;
  max-width: 220px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
}

/* ---------- Login ---------- */
.login-wrap {
  max-width: 380px;
  margin: 60px auto 0;
}
.login-wrap h1 {
  text-align: center;
  font-size: 22px;
  margin-bottom: 4px;
}
.login-wrap p.sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 0;
  margin-bottom: 24px;
}

/* ---------- Tables / lists ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.resolved { background: var(--success-bg); color: var(--success); }
.badge.pending { background: var(--warning-bg); color: #c2410c; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-actions {
  display: flex;
  gap: 8px;
}

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

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 10px;
  font-size: 14px;
}

.usage-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 6px;
}
.usage-bar-fill {
  height: 100%;
  background: var(--primary);
}
