:root {
  --primary: #0f4c81;
  --primary-dark: #0a3559;
  --primary-light: #e8f1f8;
  --accent: #f59e0b;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #dbe4ef;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(15, 76, 129, 0.08);
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Layout */
.dashboard-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-mark--lg {
  width: 56px;
  height: 56px;
  font-size: 1.5rem;
  margin: 0 auto 1rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 1.05rem;
}

.sidebar-brand span {
  font-size: 0.75rem;
  opacity: 0.75;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  padding: 1rem 0.75rem 0.35rem;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-weight: 600;
}

.nav-item--danger:hover {
  background: rgba(220, 38, 38, 0.25);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.dashboard-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--text);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
  display: block;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.topbar-title p {
  margin: 0.15rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
}

.page-content {
  padding: 1.5rem;
}

/* Messages */
.messages {
  padding: 0 1.5rem;
  margin-top: 1rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.alert--success, .alert--info {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.alert--error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(15, 76, 129, 0.12);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
}

.stat-icon svg {
  width: 22px;
  height: 22px;
}

.stat-count {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--primary-dark);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Panels */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel--form {
  max-width: 720px;
}

.panel--narrow {
  max-width: 480px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

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

.data-table th,
.data-table td {
  padding: 0.75rem 1.25rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  background: #fafbfc;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.table-link {
  color: var(--primary);
  font-weight: 500;
}

.table-link:hover {
  text-decoration: underline;
}

.col-actions {
  white-space: nowrap;
  text-align: right !important;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.thumb-placeholder {
  color: var(--text-muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  max-width: 400px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-bar__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.filter-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

.filter-btn--active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

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

.btn--primary:hover {
  background: var(--primary-dark);
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  background: #f3f4f6;
}

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

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

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

.btn--block {
  width: 100%;
}

/* Forms */
.entity-form,
.login-form {
  padding: 1.5rem;
}

.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-control,
.form-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.12);
}

.form-group.has-error .form-control {
  border-color: var(--danger);
}

.form-note {
  margin: 0 0 1.1rem;
  padding: 0.75rem 1rem;
  background: var(--primary-light);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--primary-dark);
}

.field-error {
  display: block;
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.help-text {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.5rem;
}

.current-image {
  margin-bottom: 1.25rem;
}

.current-image label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.current-image img {
  max-width: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Empty state */
.empty-state {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 1rem;
}

.empty-state__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Bulk upload */
.bulk-upload-form {
  padding: 1.5rem;
}

.upload-dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: #fafbfc;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-dropzone:hover,
.upload-dropzone--active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-dropzone__icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.upload-dropzone__title {
  margin: 0 0 0.25rem;
  font-weight: 600;
  color: var(--primary-dark);
}

.upload-dropzone__hint {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.upload-dropzone__input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-preview {
  margin-top: 1.25rem;
}

.upload-preview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.upload-preview__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.upload-preview__item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.upload-preview__item img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  background: #f8fafc;
  display: block;
}

.upload-preview__name {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-preview__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.upload-preview__remove:hover {
  background: var(--danger);
}

.alert--warning {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.detail-list {
  margin: 0;
  padding: 1.5rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-row dt {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-row dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
  white-space: pre-wrap;
}

.detail-attachment {
  padding: 0 1.5rem 1rem;
}

@media (max-width: 600px) {
  .detail-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

/* Quick actions */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.25rem;
}

.action-card {
  padding: 0.85rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--primary);
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.action-card:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Delete */
.delete-box {
  padding: 1.5rem;
}

.delete-box p {
  margin: 0 0 1rem;
}

.delete-preview {
  max-width: 160px;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

/* Login */
.login-body {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand h1 {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
  color: var(--primary-dark);
}

.login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .dashboard-main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: grid;
    place-items: center;
  }

  .user-name {
    display: none;
  }
}

@media (max-width: 600px) {
  .page-content {
    padding: 1rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-form {
    max-width: none;
  }

  .col-actions .btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
}
