* { box-sizing: border-box; }

:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --border: #e5e8ef;
  --border-strong: #d4d9e3;
  --text: #16181d;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --success-bg: #ecfdf5;
  --success-text: #047857;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --sidebar-bg: #101322;
  --sidebar-text: #9ba3b7;
  --shadow-sm: 0 1px 2px rgba(16, 19, 34, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 19, 34, 0.08);
  --radius: 12px;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }

/* ---------- Сайдбар ---------- */

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  padding: 2px 10px 22px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}
.brand-text { font-weight: 700; font-size: 15.5px; line-height: 1.2; letter-spacing: 0.01em; }

.sidebar nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.sidebar nav a.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.nav-icon { display: flex; align-items: center; }

.userbox {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 14px;
  padding: 14px 6px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2a2f45;
  color: #c7cbe0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}
.userinfo { flex: 1; min-width: 0; }
.username {
  font-weight: 600;
  color: #fff;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.userrole { font-size: 12px; color: var(--sidebar-text); }
.btn-logout {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  transition: background 0.15s, color 0.15s;
}
.btn-logout:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* ---------- Контент ---------- */

.content { flex: 1; min-width: 0; }
.container { max-width: 1160px; margin: 0 auto; padding: 28px 28px 56px; }

h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 18px; }
h2 {
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2 .icon { color: var(--muted); }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }

.title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.title-row h1 { margin: 0; }
.page-head .title-row { margin-bottom: 0; }
.btn-back {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-back:hover { background: #f4f5f9; color: var(--text); border-color: #c3c9d6; text-decoration: none; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.muted { color: var(--muted); }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

/* ---------- Таблиці ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: #f8f9fc; }

.qty-low { color: var(--danger); font-weight: 700; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sort-asc::after { content: ' ▲'; font-size: 9px; color: var(--primary); }
th.sort-desc::after { content: ' ▼'; font-size: 9px; color: var(--primary); }

.pager {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pager-info { color: var(--muted); font-size: 13px; margin-right: auto; }
.pager-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.pager-btn:hover:not(:disabled) { background: #f4f5f9; border-color: #c3c9d6; }
.pager-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-btn:disabled { opacity: 0.4; cursor: default; }
.pager-dots { color: var(--muted); padding: 0 2px; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: #f4f5f9; text-decoration: none; border-color: #c3c9d6; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--surface); border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: var(--error-bg); border-color: var(--danger); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Повідомлення ---------- */

.flash {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: #a7f3d0; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: #fecaca; }

/* ---------- Форми ---------- */

label { display: block; font-weight: 550; font-size: 13px; color: #3f4451; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: #9aa1af; }
textarea { resize: vertical; max-height: 400px; min-height: 60px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-card { max-width: 720px; overflow: visible; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .span2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 130px; }
.inline-form button { flex-shrink: 0; }

.searchbar { display: flex; gap: 8px; margin-bottom: 18px; max-width: 680px; }
.searchbar input { margin-top: 0; }
.searchbar select { margin-top: 0; width: auto; }
.searchbar form { flex-shrink: 0; }

/* ---------- Комбобокс ---------- */

.combo { position: relative; margin-top: 6px; }
.combo .combo-input { margin-top: 0; }
.combo-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 5px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: var(--shadow-md);
}
.combo-item { padding: 9px 12px; cursor: pointer; font-weight: 400; }
.combo-item:hover { background: var(--primary-soft); }
.combo-empty::after {
  content: 'Нічого не знайдено';
  display: block;
  padding: 9px 12px;
  color: var(--muted);
  font-weight: 400;
}
.combo-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important; }

/* ---------- Панель ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.stat:hover { text-decoration: none; border-color: var(--primary); box-shadow: var(--shadow-md); }
.stat-num { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }

/* ---------- Деталі ---------- */

.details { display: grid; grid-template-columns: 180px 1fr; gap: 10px 18px; margin: 0; }
.details dt { color: var(--muted); font-size: 13.5px; }
.details dd { margin: 0; font-weight: 500; }

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
}

.role-badge {
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 2.5px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-block;
}

/* ---------- Вхід ---------- */

.login-wrap { min-height: 88vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 390px; padding: 32px; box-shadow: var(--shadow-md); }
.login-card h1 {
  text-align: center;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.login-card .brand-mark { width: 42px; height: 42px; }
.login-card p { text-align: center; margin-top: 2px; }
.login-card label { margin-bottom: 14px; }

/* ---------- Адаптивність ---------- */

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 12px 14px; }
  .brand { padding-bottom: 10px; }
  .brand-text br { display: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .userbox { margin-top: 8px; padding-top: 10px; }
  .container { padding: 20px 16px 40px; }
  .form-grid, .grid2 { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .details { grid-template-columns: 1fr; }
}
