/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2e3348;
  --accent:     #4f7df3;
  --accent-dim: #3a5ec0;
  --danger:     #e05252;
  --danger-dim: #b83d3d;
  --success:    #3ecf6e;
  --warning:    #f0a030;
  --text:       #e2e6f0;
  --text-muted: #7a8099;
  --text-faint: #4a5068;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: #a8c4ff;
}

small.muted { color: var(--text-muted); font-size: 0.8em; }

/* ─── Navbar ────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.nav-brand svg { color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.nav-link {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--text); background: var(--surface2); text-decoration: none; }

.nav-link-accent {
  background: var(--accent);
  color: #fff !important;
  padding: 0.35rem 0.9rem;
}

.nav-link-accent:hover { background: var(--accent-dim) !important; }

.nav-link-logout {
  color: var(--danger);
  font-size: 0.82rem;
}

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

.nav-username {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.role-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
}

.role-preventor { background: rgba(79,125,243,0.2); color: var(--accent); }
.role-viewer    { background: rgba(122,128,153,0.2); color: var(--text-muted); }

/* ─── Main Content ──────────────────────────────────────────── */
.main-content {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.main-content.no-nav { padding-top: 0; }

/* ─── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 0.2rem;
}

.page-subtitle a { color: var(--text-muted); }
.page-subtitle a:hover { color: var(--accent); }

/* ─── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 4px solid;
}

.alert-error   { background: rgba(224,82,82,0.1);  border-color: var(--danger);  color: #f59090; }
.alert-success { background: rgba(62,207,110,0.1); border-color: var(--success); color: #6feaa0; }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none !important;
  white-space: nowrap;
  user-select: none;
}

.btn:active { opacity: 0.85; }

.btn-primary   { background: var(--accent);   color: #fff; }
.btn-primary:hover { background: var(--accent-dim); }

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

.btn-outline   { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: rgba(79,125,243,0.1); }

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

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

.btn-full { width: 100%; justify-content: center; padding: 0.7rem 1rem; font-size: 0.95rem; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

.action-group { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ─── Search Bar ────────────────────────────────────────────── */
.search-bar { margin-bottom: 1.25rem; }

.search-input-wrap {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 220px;
  padding: 0.55rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-faint); }

/* ─── Table ─────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead th {
  padding: 0.8rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.data-table thead th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(79,125,243,0.04); }

.data-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  color: var(--text);
}

.td-img { width: 70px; }

.empty-row { text-align: center; color: var(--text-muted); padding: 3rem 1rem !important; font-style: italic; }

.id-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-faint);
  font-family: monospace;
}

.motivo-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(240,160,48,0.15);
  color: var(--warning);
  white-space: nowrap;
}

/* ─── Thumbnail ─────────────────────────────────────────────── */
.thumb {
  width: 52px;
  height: 42px;
  object-fit: cover;
  border-radius: 5px;
  cursor: zoom-in;
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s;
  display: block;
}

.thumb:hover { transform: scale(1.08); border-color: var(--accent); }

.no-img { color: var(--text-faint); font-size: 1.1rem; }

/* ─── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.page-link {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  text-decoration: none !important;
}

.page-link:hover { background: var(--surface2); color: var(--text); }
.page-link.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Form ──────────────────────────────────────────────────── */
.record-form { }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

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

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.required { color: var(--danger); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.6rem 0.85rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,125,243,0.12);
}

.form-group select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8099' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-group textarea { resize: vertical; min-height: 100px; }

.form-group input[type="file"] {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.file-input { color: var(--text-muted); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 0.5rem;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-weight: 400 !important;
}

.checkbox-label input { width: auto; }

.current-img-preview {
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.current-img-preview img {
  max-width: 180px;
  max-height: 140px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: transform 0.15s;
}

.current-img-preview img:hover { transform: scale(1.03); }

.img-new-preview img {
  max-width: 220px;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 2px solid var(--accent);
  margin-top: 0.5rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ─── Detail Page ───────────────────────────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .detail-layout { grid-template-columns: 1fr; }
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-field-full {
  grid-column: 1 / -1;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

.detail-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 0.95rem;
  color: var(--text);
}

.detail-textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 0.25rem;
}

.detail-image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.detail-img {
  width: 100%;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 0.75rem;
  display: block;
}

.detail-img:hover { transform: scale(1.015); box-shadow: var(--shadow); }

.no-img-large {
  text-align: center;
  color: var(--text-faint);
  font-style: italic;
  padding: 3rem 1rem;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

/* ─── Auth Page ─────────────────────────────────────────────── */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: radial-gradient(ellipse at 60% 30%, rgba(79,125,243,0.06) 0%, transparent 70%), var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  color: var(--accent);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.2rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

/* ─── Modal ─────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal.active { display: flex; }

.modal-content {
  position: relative;
  max-width: min(90vw, 1100px);
  max-height: 90vh;
}

.modal-content img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  display: block;
}

.modal-close {
  position: absolute;
  top: -0.75rem;
  right: -0.75rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 1;
}

.modal-close:hover { background: var(--danger-dim); }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { padding: 0 1rem; gap: 0.75rem; }
  .nav-brand span { display: none; }
  .nav-username { display: none; }
  .main-content { padding: 1.25rem 1rem 3rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: 0.82rem; }
  .data-table thead th,
  .data-table td { padding: 0.6rem 0.65rem; }
}

@media (max-width: 480px) {
  .auth-card { padding: 1.75rem 1.25rem; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
