/* =========================================================
   MIBI Admin Tools — Stylesheet
   ========================================================= */

:root {
  --sidebar-bg:       #1a1d21;
  --sidebar-border:   #2a2d33;
  --sidebar-text:     #8a93a2;
  --sidebar-hover-bg: #22262d;
  --sidebar-active-bg:#2563eb;
  --sidebar-active:   #ffffff;
  --sidebar-width:    240px;

  --bg:               #f0f2f6;
  --card-bg:          #ffffff;
  --border:           #e2e6ea;
  --border-focus:     #2563eb;

  --text:             #1a1d21;
  --text-muted:       #6b7280;
  --text-sm:          0.8125rem;

  --primary:          #2563eb;
  --primary-hover:    #1d4ed8;
  --secondary-bg:     #f3f4f6;
  --secondary-hover:  #e5e7eb;
  --danger:           #dc2626;
  --danger-hover:     #b91c1c;
  --success:          #16a34a;

  --radius:           6px;
  --radius-lg:        10px;
  --shadow:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:        0 4px 16px rgba(0,0,0,.12);

  --transition:       150ms ease;
}

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

html { font-size: 15px; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

code {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.8em;
  background: #f3f4f6;
  padding: 2px 5px;
  border-radius: 3px;
  color: #374151;
}

/* ─── Layout ───────────────────────────────────────────── */

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

.main-content {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
  overflow-x: auto;
}

/* ─── Sidebar ───────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo::after {
  content: 'M';
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-title {
  color: #ffffff;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--sidebar-text);
  padding: 12px 8px 4px;
  margin-top: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  color: #d1d5db;
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}

.sidebar-icon {
  width: 16px;
  height: 16px;
  opacity: .75;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  flex-shrink: 0;
}

/* Icon SVGs inline via mask */
.icon-grid::before   { content: '⊞'; font-size: 14px; }
.icon-tag::before    { content: '⊟'; font-size: 14px; }
.icon-truck::before  { content: '⊡'; font-size: 14px; }
.icon-users::before  { content: '⊹'; font-size: 14px; }

.sidebar-link .sidebar-icon::before {
  display: block;
  color: currentColor;
}

/* Use simpler text icons */
.icon-grid::before   { content: '▦'; }
.icon-tag::before    { content: '◈'; }
.icon-truck::before  { content: '◫'; }
.icon-users::before  { content: '◉'; }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 14px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  color: var(--sidebar-text);
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  text-decoration: none;
  transition: color var(--transition);
}
.sidebar-logout:hover { color: #d1d5db; text-decoration: none; }

/* ─── Auth pages ─────────────────────────────────────────── */

.auth-body {
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: 10px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-logo::after {
  content: 'M';
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}

.auth-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

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

.auth-footer-link {
  margin-top: 20px;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ─── Page header ────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.page-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 3px;
}

/* ─── Filter bar ─────────────────────────────────────────── */

.filter-bar {
  margin-bottom: 16px;
}

.filter-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-select-wrap { position: relative; }

.filter-count {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-left: auto;
}

/* ─── Card ───────────────────────────────────────────────── */

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* ─── Table ──────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

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

.data-table th {
  text-align: left;
  padding: 11px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f3f5;
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

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

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.col-actions .btn + .btn { margin-left: 6px; }

.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px !important;
  font-size: var(--text-sm);
}

/* ─── Inline edit ────────────────────────────────────────── */

.inline-edit-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 0;
}

.inline-edit-fields {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  align-items: flex-end;
}

.form-group-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.form-group-inline.form-group-wide { flex: 1; min-width: 200px; }

.inline-edit-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-bottom: 1px;
}

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

/* ─── Forms ──────────────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-group-half { flex: 1; }

.form-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label-link {
  font-size: var(--text-sm);
  color: var(--primary);
}

.form-control,
.form-select {
  display: block;
  width: 100%;
  padding: 8px 11px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  line-height: 1.4;
}

.form-control::placeholder { color: #adb5bd; }

.form-control:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-select {
  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='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

.form-control-sm,
.form-select-sm {
  padding: 5px 8px;
  font-size: 0.8125rem;
}

.input-password-wrap { position: relative; }

.input-password-wrap .form-control { padding-right: 40px; }

.input-password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 0;
}
.input-password-toggle:hover { color: var(--text); }

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

/* ─── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  -webkit-appearance: none;
}

.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; color: #fff; }

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); text-decoration: none; color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: #fca5a5;
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; border-color: var(--danger); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--secondary-bg); color: var(--text); text-decoration: none; }

.btn-block { width: 100%; }

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8125rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}
.link-btn:hover { color: var(--primary-hover); }

/* ─── Badges ─────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-blue  { background: #dbeafe; color: #1d4ed8; }
.badge-grey  { background: #f3f4f6; color: #4b5563; }
.badge-green { background: #dcfce7; color: #15803d; }

/* ─── Alerts ─────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-icon {
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: .6;
  font-size: 12px;
  flex-shrink: 0;
  padding: 0 2px;
}
.alert-close:hover { opacity: 1; }

.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

/* ─── Modal ──────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: fadeIn 120ms ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 150ms ease;
}

.modal-sm { max-width: 380px; }

@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

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

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--secondary-bg); }

.modal-body {
  padding: 20px;
}

.modal-body p { margin-bottom: 8px; font-size: var(--text-sm); color: var(--text); }
.modal-body p:last-child { margin-bottom: 0; }

.modal-detail {
  font-weight: 600 !important;
  color: var(--text) !important;
  background: var(--secondary-bg);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem !important;
  word-break: break-all;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Toast notifications ────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn 200ms ease;
  min-width: 240px;
  max-width: 360px;
}

.toast-success { background: #15803d; color: #fff; }
.toast-error   { background: #b91c1c; color: #fff; }
.toast-info    { background: var(--primary); color: #fff; }

@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Utilities ──────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.text-sm    { font-size: var(--text-sm); }

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 16px; }
  .inline-edit-fields { flex-direction: column; }
  .form-row { flex-direction: column; }
  .page-header { flex-direction: column; align-items: stretch; }
  .filter-form { flex-direction: column; align-items: stretch; }
  .filter-count { margin-left: 0; }
}
