:root {
  --bg: #eef1f8;
  --sidebar-bg: #ffffff;
  --topbar-bg: #ffffff;
  --border: #e6e9f2;
  --text: #1f2430;
  --text-muted: #8a90a2;
  --card-bg: #ffffff;
  --card-shadow: 0 6px 18px rgba(20, 30, 60, 0.06);
  --menu-text: #4b5568;
  --menu-active-bg: #2f66f0;
  --menu-active-text: #ffffff;
  --accent: #2f66f0;
  --accent-soft-bg: #dbe6fe;
  --accent-soft-text: #2f66f0;
  --pill-bg: #eef1f8;
  --pill-inactive-bg: #ffffff;
  --input-bg: #ffffff;
  --input-border: #e1e5f0;
  --danger: #e34350;
  --success: #22a35a;
}

html[data-theme="dark"] {
  --bg: #0e0a1a;
  --sidebar-bg: #140d24;
  --topbar-bg: #140d24;
  --border: #241a3a;
  --text: #f1eefb;
  --text-muted: #9a90b8;
  --card-bg: #180f2b;
  --card-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  --menu-text: #b5aad0;
  --menu-active-bg: linear-gradient(135deg, #7c3aed, #a855f7);
  --menu-active-text: #ffffff;
  --accent: #9d5cf5;
  --accent-soft-bg: #2a1b45;
  --accent-soft-text: #c9a9ff;
  --pill-bg: #140d24;
  --pill-inactive-bg: #1c1330;
  --input-bg: #1c1330;
  --input-border: #2c2048;
  --danger: #f0616d;
  --success: #3ecb85;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s ease, color .2s ease;
}

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

.app-shell { display: flex; min-height: 100vh; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
}
.topbar-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.topbar-logo img { width: 32px; height: 32px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: 18px; }

.bell-wrap { position: relative; }
.bell-btn {
  background: none; border: none; cursor: pointer; position: relative;
  color: var(--text); font-size: 20px; display: flex; align-items: center;
}
.bell-badge {
  position: absolute; top: -6px; right: -8px; background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 999px; min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.bell-dropdown {
  position: absolute; right: 0; top: 36px; width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--card-shadow); display: none; z-index: 50;
}
.bell-dropdown.open { display: block; }
.bell-dropdown-header { padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--border); }
.bell-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.bell-item:last-child { border-bottom: none; }
.bell-item.unread { background: var(--accent-soft-bg); }
.bell-item-title { font-weight: 600; margin-bottom: 2px; }
.bell-item-time { color: var(--text-muted); font-size: 11px; margin-top: 4px; }
.bell-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

.theme-switch { display: flex; align-items: center; gap: 8px; background: var(--pill-bg); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 13px; }
.switch { position: relative; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #cbd3e6; border-radius: 999px; transition: .2s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
input:checked + .slider { background: var(--accent); }
input:checked + .slider:before { transform: translateX(18px); }

/* Sidebar */
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  padding: 20px 16px; display: flex; flex-direction: column; justify-content: space-between;
  min-height: calc(100vh - 0px);
}
.menu { display: flex; flex-direction: column; gap: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px;
  color: var(--menu-text); font-weight: 600; font-size: 14.5px; cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.menu-item .icon { width: 20px; text-align: center; }
.menu-item:hover { background: var(--accent-soft-bg); }
.menu-item.active { background: var(--menu-active-bg); color: var(--menu-active-text); }

.admin-box { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--pill-inactive-bg); border: 1px solid var(--border); }
.admin-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg,#6d5df5,#2f66f0); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.admin-name { font-weight: 700; font-size: 14px; }
.admin-email { font-size: 12px; color: var(--text-muted); }

/* Main content */
.main { flex: 1; padding: 28px 32px; }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--accent); }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 22px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 10px;
  font-weight: 600; font-size: 14px; cursor: pointer; border: none; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .92; }
.btn-outline { background: transparent; border: 1px solid var(--input-border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: #25D366; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; }

/* Tabs / switcher */
.tabs { display: inline-flex; background: var(--pill-bg); padding: 6px; border-radius: 14px; gap: 4px; margin: 0 auto 28px; }
.tab-btn {
  padding: 10px 22px; border-radius: 10px; font-weight: 700; font-size: 14px; border: none; cursor: pointer;
  background: var(--pill-inactive-bg); color: var(--text); display: flex; align-items: center; gap: 8px;
}
.tab-btn.active { background: var(--menu-active-bg); color: #fff; }
.tabs-center { display: flex; justify-content: center; }

/* Card grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px; }
.entity-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--card-shadow);
  padding: 26px 16px 18px; display: flex; flex-direction: column; align-items: center; gap: 14px; cursor: pointer;
  position: relative; transition: transform .15s ease;
}
.entity-card:hover { transform: translateY(-3px); }
.entity-card img { width: 74px; height: 74px; object-fit: contain; border-radius: 16px; }
.entity-card .name { font-weight: 700; font-size: 14px; text-align: center; }
.count-badge {
  background: var(--accent-soft-bg); color: var(--accent-soft-text); font-weight: 700; font-size: 13px;
  padding: 4px 14px; border-radius: 999px;
}

/* Tables */
.table-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: var(--card-shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 700; text-transform: uppercase; font-size: 11.5px; letter-spacing: .04em; background: var(--pill-bg); }
tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 8px; }

.badge-days { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-ok { background: var(--accent-soft-bg); color: var(--accent-soft-text); }
.badge-warn { background: #fff2d6; color: #a16207; }
.badge-danger { background: #ffe1e3; color: #b0212c; }
html[data-theme="dark"] .badge-warn { background: #3a2a12; color: #fbbf24; }
html[data-theme="dark"] .badge-danger { background: #3a1620; color: #f87171; }

/* Forms */
.form-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: var(--card-shadow); max-width: 640px; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.form-control {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--input-border);
  background: var(--input-bg); color: var(--text); font-size: 14px;
}
textarea.form-control { resize: vertical; min-height: 90px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.select-with-add { display: flex; gap: 8px; align-items: flex-end; }
.select-with-add .form-group { flex: 1; margin-bottom: 0; }
.add-inline-btn {
  width: 44px; height: 44px; border-radius: 10px; border: 1px dashed var(--accent); background: var(--accent-soft-bg);
  color: var(--accent); font-size: 20px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.error-text { font-size: 12px; color: var(--danger); margin-top: 4px; }

.image-preview { width: 70px; height: 70px; border-radius: 14px; object-fit: cover; border: 1px solid var(--border); margin-bottom: 10px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 8, 20, .55); display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box { background: var(--card-bg); border-radius: 18px; padding: 26px; width: 420px; max-width: 92vw; box-shadow: var(--card-shadow); }
.modal-title { font-weight: 700; font-size: 17px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.alert-box { padding: 12px 18px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; font-weight: 600; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-danger { background: #fee2e2; color: #b91c1c; }
html[data-theme="dark"] .alert-success { background: #123322; color: #4ade80; }
html[data-theme="dark"] .alert-danger { background: #3a1620; color: #f87171; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 380px; max-width: 92vw; background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; padding: 36px; box-shadow: var(--card-shadow); }
.login-logo { text-align: center; margin-bottom: 24px; font-weight: 800; font-size: 22px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 18px; }
}
