:root {
  --bg: #eef3fb;
  --surface: #ffffff;
  --line: #d8e2f0;
  --ink: #1f2a37;
  --muted: #5f6f85;
  --brand: #0b4ea2;
  --brand-2: #1565c0;
  --danger: #d92d20;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f6f9ff, #eef3fb);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(11, 78, 162, 0.12);
}

.login-card h1 {
  margin: 0;
  color: var(--brand);
}

.login-card p {
  margin: 6px 0 14px;
  color: var(--muted);
}

.login-card small {
  color: var(--muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 18px 24px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}

.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar p { margin: 2px 0 0; opacity: 0.9; font-size: 0.92rem; }

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.session-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-info span {
  font-size: 0.82rem;
  opacity: 0.95;
}

.api-config {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.api-config label { font-size: 0.8rem; font-weight: 700; opacity: 0.95; }
.api-config input { min-width: 260px; }

.layout {
  max-width: 1280px;
  margin: 18px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
}

.tabs {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  height: fit-content;
  position: sticky;
  top: 10px;
}

.tab {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

.tab:hover { background: #f3f6fc; }
.tab.active { background: #e5eefc; color: var(--brand); }

.content { min-width: 0; }

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.panel.active { display: block; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.panel-head h2 { margin: 0; font-size: 1.1rem; }
.counter { font-size: 0.83rem; color: var(--muted); }

.subsection {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.subsection h3 { margin: 0 0 8px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.single-col {
  grid-template-columns: 1fr;
}

.full { grid-column: 1 / -1; }

input, select, textarea, button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
}

textarea { min-height: 72px; resize: vertical; }
button { cursor: pointer; }

button.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  font-weight: 700;
}

button.secondary {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  font-weight: 600;
}

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

.filters {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 8px;
  margin-bottom: 10px;
}

.filters input,
.filters select {
  background: #f9fbff;
}

.item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
  padding: 10px;
}

.item-title { margin: 0; font-size: 0.95rem; font-weight: 700; }
.item-sub { margin: 2px 0 0; font-size: 0.84rem; color: var(--muted); }

.item-actions { display: flex; align-items: flex-start; gap: 6px; }

.item-actions button {
  border: 0;
  color: #fff;
  padding: 7px 10px;
  font-size: 0.8rem;
}

.item-actions .edit { background: #2563eb; }
.item-actions .delete { background: var(--danger); }

.toast {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  background: #e8f5e9;
  color: #1f6f35;
  border: 1px solid #b9e3c0;
}

.toast.error {
  background: #fdecea;
  color: #9b1c1c;
  border-color: #f7c2bf;
}

.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 22, 38, 0.48);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 30px 60px rgba(16, 33, 60, 0.32);
  padding: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.modal-head h3 {
  margin: 0;
  color: var(--brand);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0;
}

.field-group {
  display: grid;
  gap: 6px;
}

.field-group label {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 600;
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .tabs {
    position: static;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 14px; }
  .topbar-actions { width: 100%; align-items: stretch; }
  .api-config input { min-width: 100%; }
  .tabs { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}
