:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --line: #dde5ef;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --danger: #b91c1c;
  --success: #166534;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #94a3b8;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

a {
  color: var(--primary-2);
}

img {
  max-width: 100%;
  height: auto;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 18px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1100;
}

.sidebar a {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  transition: background .2s ease, color .2s ease;
  word-break: break-word;
}

.sidebar a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.brand {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  padding-right: 42px;
  word-break: break-word;
}

.tenant {
  margin: 10px 0 18px;
  color: var(--sidebar-muted);
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.nav-title {
  color: var(--sidebar-muted);
  font-size: 12px;
  text-transform: uppercase;
  margin: 18px 10px 8px;
  font-weight: 700;
  letter-spacing: .04em;
}

.content {
  padding: 24px;
  min-width: 0;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.topbar-title {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  word-break: break-word;
}

.topbar-user {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar-user-info {
  color: var(--text);
  word-break: break-word;
}

.topbar-role {
  margin-left: 8px;
  opacity: .7;
}

.logout-link {
  text-decoration: none;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(15,23,42,.03);
  min-width: 0;
  overflow: hidden;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  min-width: 0;
}

.stat strong {
  font-size: 26px;
  display: block;
  margin-top: 8px;
  word-break: break-word;
}

.muted {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  min-width: 560px;
}

form .row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

form .row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

/* FIX I RREGULLUAR PËR FUSHAT */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  min-width: 0;
}

.field label {
  display: block;
  font-weight: 700;
  margin: 0;
}

.field input,
.field select,
.field textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
}

.field textarea {
  min-height: 100px;
  resize: vertical;
}

/* KLASA TË REJA PËR FORMA MODERNE */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field-full {
  grid-column: 1 / -1;
}

button,
.btn {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border: none;
  cursor: pointer;
}

.btn-secondary {
  background: #475569;
}

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

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  word-break: break-word;
}

.alert-success {
  background: #dcfce7;
  color: #14532d;
  border-color: #bbf7d0;
}

.alert-error {
  background: #fee2e2;
  color: #7f1d1d;
  border-color: #fecaca;
}

.kpi {
  font-size: 12px;
  color: var(--muted);
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #f8fafc;
  padding: 3px 6px;
  border-radius: 6px;
}

.small {
  font-size: 12px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
}

/* mobile nav hidden on desktop */
.mobile-topbar {
  display: none;
}

.mobile-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-brand-wrap {
  min-width: 0;
}

.mobile-brand {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
  line-height: 1.2;
}

.mobile-tenant {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.menu-toggle {
  appearance: none;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex: 0 0 auto;
}

.sidebar-close-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

/* desktop hard fix */
@media (min-width: 993px) {
  .layout {
    display: grid !important;
    grid-template-columns: 280px minmax(0, 1fr) !important;
  }

  .sidebar {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    height: 100vh !important;
    display: block !important;
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .mobile-topbar {
    display: none !important;
  }

  .sidebar-close-btn {
    display: none !important;
  }

  body {
    overflow: auto !important;
  }
}

@media (max-width: 1100px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 992px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 1200;
  }

  .layout {
    display: block !important;
  }

  .sidebar {
    display: block;
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .28s ease;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    z-index: 1300;
  }

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

  .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.08);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17,24,39,.45);
    z-index: 1290;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: 16px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 18px;
  }

  .topbar-title {
    width: 100%;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar-user {
    width: 100%;
    justify-content: space-between;
    align-items: flex-start;
  }

  .grid-2,
  .grid-3,
  form .row,
  form .row-3,
  .form-grid,
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 14px;
  }

  .mobile-topbar {
    padding: 12px 14px;
  }

  .mobile-brand {
    font-size: 15px;
  }

  .mobile-tenant {
    max-width: 150px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .stats {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat {
    padding: 16px;
  }

  .stat strong {
    font-size: 22px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .sidebar {
    width: 280px;
    max-width: 88vw;
  }

  th,
  td {
    padding: 9px 10px;
  }

  .table-wrap table {
    min-width: 480px;
  }
}