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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f9;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #f4f6f9;
}

.login-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 16px;
  padding: 2.5rem 2rem; width: 100%; max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08); text-align: center;
}

.login-logo  { font-size: 2.5rem; margin-bottom: 0.75rem; }
.login-title { font-size: 1.4rem; font-weight: 700; color: #1a1a2e; }
.login-sub   { color: #64748b; font-size: 0.9rem; margin: 0.3rem 0 1.5rem; }

.login-error {
  background: #fee2e2; border: 1px solid #fca5a5; border-radius: 8px;
  color: #991b1b; font-size: 0.875rem; padding: 0.6rem 0.9rem;
  margin-bottom: 1.25rem; text-align: left;
}

.login-field { text-align: left; margin-bottom: 1rem; }
.login-field label {
  display: block; font-size: 0.8rem; font-weight: 600;
  color: #475569; text-transform: uppercase; letter-spacing: 0.4px;
  margin-bottom: 0.35rem;
}
.login-field input {
  width: 100%; padding: 0.55rem 0.85rem;
  border: 1px solid #e2e8f0; border-radius: 8px;
  font-size: 0.95rem; color: #1a1a2e; background: #f8fafc;
  outline: none; transition: border-color 0.15s, background 0.15s;
}
.login-field input:focus { border-color: #6366f1; background: #fff; }

.login-btn {
  width: 100%; padding: 0.65rem;
  background: #6366f1; color: #fff;
  border: none; border-radius: 8px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  margin-top: 0.5rem; transition: background 0.15s;
}
.login-btn:hover { background: #4f46e5; }

/* ── Nav user/logout ──────────────────────────────────────────────────────── */
.nav-user {
  margin-left: auto; display: flex; align-items: center;
  gap: 0.75rem; font-size: 0.875rem; color: #cbd5e1;
}

.nav-logout {
  color: #94a3b8; text-decoration: none;
  padding: 0.3rem 0.7rem; border: 1px solid #374151;
  border-radius: 6px; font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}
.nav-logout:hover { background: #374151; color: #fff; }

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  background: #1a1a2e;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

nav ul { list-style: none; display: flex; gap: 0.25rem; }

nav ul a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

nav ul a:hover { background: #2d2d4e; color: #fff; }

/* ── Nav dropdown ─────────────────────────────────────────────────────────── */
.nav-dropdown { position: relative; }

.nav-dropdown-trigger { cursor: pointer; user-select: none; }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #1a1a2e;
  border: 1px solid #2d2d4e;
  border-radius: 8px;
  padding: 0.35rem 0;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 200;
  flex-direction: column;
  gap: 0;
}

.nav-dropdown:hover .nav-dropdown-menu { display: flex; }

.nav-dropdown-menu li { list-style: none; }

.nav-dropdown-menu a {
  display: block;
  padding: 0.45rem 1rem;
  border-radius: 0;
  white-space: nowrap;
  font-size: 0.875rem;
}

.nav-dropdown-menu a:hover { background: #2d2d4e; color: #fff; }

/* ── Main content ─────────────────────────────────────────────────────────── */
main { padding: 2rem; max-width: 1400px; margin: 0 auto; }

.page-header { margin-bottom: 1.75rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; }
.page-header p { color: #64748b; margin-top: 0.25rem; }

/* ── Home card grid ───────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: pointer;
}

.card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.1); transform: translateY(-2px); }
.card.disabled { opacity: 0.5; cursor: default; pointer-events: none; }

.card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.card h2 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.card p { font-size: 0.875rem; color: #64748b; line-height: 1.5; }

/* ── Explorer layout ──────────────────────────────────────────────────────── */
.explorer-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  height: calc(100vh - 160px);
}

/* Left panel */
.table-list-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-header input {
  padding: 0.35rem 0.6rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  width: 100%;
}

.panel-header input:focus { border-color: #6366f1; }

.table-list { overflow-y: auto; flex: 1; padding: 0.5rem 0; }

.type-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 1px;
  padding: 0.6rem 1rem 0.2rem;
  text-transform: uppercase;
}

.table-item {
  padding: 0.45rem 1rem;
  font-size: 0.875rem;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-item:hover { background: #f1f5f9; }
.table-item.active { background: #eef2ff; color: #4f46e5; font-weight: 600; }

/* Right panel */
.detail-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.5rem;
  overflow-y: auto;
}

.placeholder {
  color: #94a3b8;
  font-size: 1rem;
  padding-top: 3rem;
  text-align: center;
}

#detailTitle {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: #1a1a2e;
}

#detailContent h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  margin: 1.5rem 0 0.75rem;
}

.subtitle { font-weight: 400; color: #94a3b8; }

/* ── Data table ───────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
}

.data-table th {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: #475569;
  white-space: nowrap;
}

.data-table td {
  border: 1px solid #e2e8f0;
  padding: 0.45rem 0.75rem;
  vertical-align: top;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tr:nth-child(even) td { background: #f8fafc; }
.data-table tr:hover td { background: #eef2ff; }

.scroll-x { overflow-x: auto; }

code {
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #4f46e5;
}

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.filter-group select {
  padding: 0.4rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #1a1a2e;
  background: #f8fafc;
  cursor: pointer;
  outline: none;
  min-width: 160px;
  transition: border-color 0.15s;
}

.filter-group select:focus { border-color: #6366f1; background: #fff; }

.btn-reset {
  padding: 0.4rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #475569;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  align-self: flex-end;
}

.btn-reset:hover { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe; }

/* ── Multi-select ─────────────────────────────────────────────────────────── */
.ms-wrap { position: relative; min-width: 180px; }

.ms-trigger {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border: 1px solid #e2e8f0; border-radius: 8px;
  background: #f8fafc; cursor: pointer;
  font-size: 0.9rem; color: #1a1a2e;
  user-select: none; gap: 0.5rem;
  transition: border-color 0.15s;
}
.ms-trigger:hover { border-color: #6366f1; background: #fff; }

.ms-arrow { font-size: 0.7rem; color: #94a3b8; flex-shrink: 0; }

.ms-dropdown {
  display: none; position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 100%; max-width: 280px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12); z-index: 300;
  overflow: hidden;
}
.ms-dropdown.open { display: block; }

.ms-search {
  display: block; width: 100%; padding: 0.5rem 0.75rem;
  border: none; border-bottom: 1px solid #e2e8f0;
  font-size: 0.85rem; outline: none; color: #1a1a2e;
}

.ms-options { max-height: 220px; overflow-y: auto; }

.ms-option {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.75rem; font-size: 0.875rem;
  cursor: pointer; color: #1a1a2e; transition: background 0.1s;
}
.ms-option:hover  { background: #f1f5f9; }
.ms-option.checked { color: #4f46e5; background: #eef2ff; }
.ms-option input  { accent-color: #6366f1; flex-shrink: 0; }

.ms-footer {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid #e2e8f0; padding: 0.4rem 0.75rem; gap: 0.5rem;
}
.ms-clear, .ms-close {
  background: none; border: none; font-size: 0.8rem; cursor: pointer; padding: 0.15rem 0.4rem; border-radius: 4px;
}
.ms-clear { color: #94a3b8; } .ms-clear:hover { color: #ef4444; }
.ms-close { color: #4f46e5; font-weight: 600; } .ms-close:hover { background: #eef2ff; }

/* ── Period toggle ────────────────────────────────────────────────────────── */
.period-toggle {
  display: flex;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}

.period-btn {
  padding: 0.4rem 0.9rem;
  border: none;
  background: #f8fafc;
  color: #475569;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border-right: 1px solid #e2e8f0;
}

.period-btn:last-child { border-right: none; }
.period-btn:hover { background: #eef2ff; color: #4f46e5; }
.period-btn.active { background: #6366f1; color: #fff; font-weight: 600; }

/* ── Article toggle button ────────────────────────────────────────────────── */
.article-toggle-btn {
  margin-left: auto;
  padding: 0.3rem 0.8rem;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  background: #f8fafc;
  color: #4f46e5;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.article-toggle-btn:hover { background: #eef2ff; border-color: #6366f1; }
.article-toggle-btn--on { background: #6366f1; color: #fff; border-color: #6366f1; }
.article-toggle-btn--on:hover { background: #4f46e5; border-color: #4f46e5; }

/* ── KPI cards ────────────────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  text-align: center;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: #4f46e5;
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.35rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Chart cards ──────────────────────────────────────────────────────────── */
.chart-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.chart-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chart-card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a2e;
}

.chart-subtitle {
  font-size: 0.825rem;
  color: #94a3b8;
}

.chart-wrap { position: relative; }

/* ── Two-column chart row ─────────────────────────────────────────────────── */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

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

/* ── Admin pages ──────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: #1a1a2e; }

.admin-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  align-items: start;
}

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

.admin-table th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #64748b;
  border-bottom: 2px solid #e2e8f0;
}

.admin-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: #334155;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f8fafc; }

.role-select {
  padding: 0.3rem 0.6rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.85rem;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
}

.role-select:focus { outline: none; border-color: #6366f1; }

.page-access { color: #64748b; font-size: 0.8rem; max-width: 380px; }

.you-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: #eef2ff;
  color: #4f46e5;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.role-admin      { background: #fef3c7; color: #92400e; }
.role-reader     { background: #dcfce7; color: #166534; }
.role-logistics  { background: #dbeafe; color: #1e40af; }
.role-production { background: #f3e8ff; color: #6b21a8; }

.admin-form { display: flex; flex-direction: column; gap: 0.9rem; }

.admin-form-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 0.75rem;
}

.admin-form-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}

.admin-form-row input,
.admin-form-row select {
  padding: 0.45rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.875rem;
  background: #f8fafc;
  color: #1a1a2e;
  width: 100%;
}

.admin-form-row input:focus,
.admin-form-row select:focus { outline: none; border-color: #6366f1; background: #fff; }

.role-description {
  font-size: 0.78rem;
  color: #64748b;
  margin-bottom: 0.6rem;
  min-height: 1.2em;
}

.btn-primary {
  padding: 0.45rem 1.2rem;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: #4f46e5; }

.admin-table-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-secondary {
  padding: 0.3rem 0.75rem;
  background: #fff;
  color: #4f46e5;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-secondary:hover { background: #eef2ff; }

.pw-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0;
}

.pw-form input {
  padding: 0.4rem 0.7rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.875rem;
  width: 220px;
}

.pw-form input:focus { outline: none; border-color: #6366f1; }

.pw-msg { font-size: 0.82rem; font-weight: 500; }
.pw-msg--error   { color: #dc2626; }
.pw-msg--success { color: #16a34a; }

.btn-danger {
  padding: 0.3rem 0.75rem;
  background: #fff;
  color: #ef4444;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover { background: #fef2f2; }

.admin-msg {
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
}

.admin-msg--error   { background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5; }
.admin-msg--success { background: #f0fdf4; color: #16a34a; border: 1px solid #86efac; }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-form-row { grid-template-columns: 1fr; }
  .admin-form-row label { margin-bottom: 0.2rem; }
}
