:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #f7fafc;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e8f0;
  --primary: #0b5cab;
  --primary-strong: #084a8a;
  --primary-soft: #e8f1fb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
}

body {
  font-family: "Segoe UI", "Noto Sans", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ---- App bar ---- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-bar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-name {
  font-size: 1.05rem;
}

.user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---- Login gate ---- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-card h1 {
  margin: 0.9rem 0 0;
  font-size: 1.4rem;
}

.login-card .subtitle {
  margin: 0.35rem 0 1.4rem;
}

.brand-mark.lg {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  font-size: 1.2rem;
}

.btn.lg {
  padding: 0.7rem 1.4rem;
  font-size: 1rem;
  width: 100%;
}

/* ---- Layout ---- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.hero h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

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

/* ---- Buttons & inputs ---- */
.btn {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: 9px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

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

.btn.sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
}

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

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

.input {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.5rem 0.7rem;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}

.input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.status {
  margin: 0.85rem 0 0;
  color: var(--muted);
  min-height: 1.25rem;
  font-size: 0.92rem;
}

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

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

/* ---- Upload ---- */
.upload-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  background: var(--surface-muted);
  transition: border-color 0.12s ease, background 0.12s ease;
}

.upload.dragover .upload-inner {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.upload-copy strong {
  font-size: 1rem;
}

/* ---- Library ---- */
.library-toolbar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.library-toolbar .search {
  flex: 1;
  min-width: 180px;
}

.report-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.report {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid transparent;
  border-radius: 10px;
}

.report:hover {
  background: var(--surface-muted);
}

.report-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}

.report-name {
  display: block;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.report-open:hover .report-name {
  text-decoration: underline;
}

.report-meta {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.1rem;
}

.report-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.report:hover .report-actions,
.report:focus-within .report-actions {
  opacity: 1;
}

.icon-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 7px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.95rem;
}

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

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

.rename-input {
  flex: 1;
  min-width: 0;
}

.empty {
  color: var(--muted);
  padding: 1.5rem 0.6rem;
  text-align: center;
  font-size: 0.92rem;
}

.external {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 0.35rem;
}

/* ---- Dialog ---- */
.dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 440px;
  width: 92vw;
  box-shadow: var(--shadow);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(16, 24, 40, 0.4);
}

.dialog-title {
  margin: 0 0 1.1rem;
  font-size: 1.15rem;
}

.dialog-text {
  margin: 0 0 1.25rem;
}

.dialog-fields {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1rem;
  max-height: 50vh;
  overflow-y: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.field-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.dialog .input {
  width: 100%;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---- Category groups ---- */
.category-header {
  list-style: none;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  padding: 0.4rem 0.6rem 0.2rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.category-header:first-child {
  margin-top: 0;
  border-top: 0;
}
