:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-alt: #fbfbfd;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);
  --primary: #0071e3;
  --primary-hover: #0068d1;
  --primary-soft: rgba(0, 113, 227, 0.08);
  --danger: #d70015;
  --danger-hover: #bb0013;
  --radius: 22px;
  --radius-sm: 12px;
  --radius-pill: 980px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.14);
  --nav-bg: rgba(255, 255, 255, 0.75);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-alt: #232325;
    --text: #f5f5f7;
    --text-muted: #8e8e93;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.16);
    --primary: #0a84ff;
    --primary-hover: #3396ff;
    --primary-soft: rgba(10, 132, 255, 0.14);
    --danger: #ff453a;
    --danger-hover: #ff6961;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
    --nav-bg: rgba(28, 28, 30, 0.72);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 400;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  transition: color 0.2s ease, background 0.2s ease;
}
.link-button:hover { color: var(--text); background: var(--surface-alt); }

.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 88px;
}

h1 { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 6px; }
h2 { font-size: 1.2rem; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 18px; }

.page-subtitle { color: var(--text-muted); margin: 0 0 36px; font-size: 1.05rem; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 26px;
}

button, input, select {
  font: inherit;
}

button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 22px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease, transform 0.1s ease;
}
button:hover { background: var(--primary-hover); }
button:active { transform: scale(0.98); }
button.secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }

input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

/* Login */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 86vh;
}
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  padding: 40px 34px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-card h1 { font-size: 1.5rem; margin: 0; }

/* Dashboard widgets */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}
.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 118px;
}
.widget-wide { grid-column: span 2; }
.widget-icon { font-size: 1.3rem; opacity: 0.85; margin-bottom: 8px; }
.widget-value {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.widget-value-sm {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.35;
  word-break: break-word;
}
.widget-label { font-size: 0.83rem; color: var(--text-muted); margin-top: 2px; }
.widget-category-list { display: flex; flex-direction: column; gap: 8px; }
.widget-category-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.widget-category-row:last-child { border-bottom: none; padding-bottom: 0; }
.widget-category-row .cat-name { color: var(--text); }
.widget-category-row .cat-count { color: var(--text-muted); font-variant-numeric: tabular-nums; font-weight: 500; }

.section-heading { margin-top: 4px; }

/* Dashboard tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 150px;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease, border-color 0.25s ease;
}
a.tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.tile-disabled { opacity: 0.5; }
.tile-icon {
  font-size: 2.1rem;
  line-height: 1;
  margin-bottom: 4px;
}
.tile-title { font-weight: 600; font-size: 1.08rem; color: var(--text); letter-spacing: -0.01em; }
.tile-desc { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }
.tile-badge {
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

/* Files module */
.back-link { display: inline-block; margin-bottom: 18px; font-size: 0.92rem; font-weight: 400; }

.upload-card { margin-bottom: 20px; }
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  padding: 18px;
  background: var(--surface-alt);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.upload-status { margin-top: 12px; font-size: 0.9rem; color: var(--text-muted); }

.filter-card { margin-bottom: 24px; }
.filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 10px;
}
@media (max-width: 700px) {
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .filters { grid-template-columns: 1fr; }
}

.file-list { display: flex; flex-direction: column; gap: 12px; }
.file-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.file-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.file-name { font-weight: 600; word-break: break-word; letter-spacing: -0.005em; }
.file-meta { display: flex; gap: 10px; flex-wrap: wrap; margin: 7px 0; font-size: 0.85rem; color: var(--text-muted); }
.file-desc { font-size: 0.9rem; color: var(--text-muted); }
.badge {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
}
.file-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-actions a, .file-actions button {
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
}
.file-actions a {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 400;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.file-actions a:hover { border-color: var(--primary); color: var(--primary); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-content { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-lg); padding: 30px; }
.modal-content label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
