:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --ink: #17202a;
  --muted: #647282;
  --line: #dbe2e8;
  --blue: #0876bb;
  --orange: #f58220;
  --green: #12805c;
  --red: #c0392b;
  --amber: #a86600;
  --shadow: 0 10px 28px rgba(18, 35, 50, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }

.sidebar {
  background: #101923;
  color: #eef5f9;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 18px 12px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4f6578 #101923;
}

.brand {
  padding: 8px 10px 20px;
  display: grid;
  gap: 8px;
}

.brand-logo {
  width: 100%;
  max-width: 205px;
  height: 70px;
  object-fit: contain;
  border-radius: 8px;
  background: #0876bb;
  padding: 4px;
}

.brand strong { font-size: 18px; }
.brand span { color: #9fb2c2; font-size: 13px; }

nav { display: grid; gap: 5px; }

nav button {
  border: 0;
  background: transparent;
  color: #cad7e1;
  text-align: left;
  padding: 11px 12px 11px 16px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  min-height: 40px;
}

nav button.active, nav button:hover {
  background: #203141;
  color: #fff;
}

nav button::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 9px;
  bottom: 9px;
  width: 4px;
  border-radius: 99px;
  background: transparent;
}

nav button.active::before,
nav button:hover::before {
  background: var(--orange);
}

.nav-group {
  margin-top: 6px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-submenu {
  display: grid;
  gap: 4px;
  margin: -1px 0 8px 12px;
  padding-left: 10px;
  border-left: 1px solid #314455;
}

.nav-submenu.hidden { display: none; }

nav button.nav-subitem {
  min-height: 34px;
  padding-top: 8px;
  padding-bottom: 8px;
  font-size: 14px;
}

.main { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-logo {
  width: 158px;
  height: 54px;
  object-fit: contain;
  border-radius: 8px;
  background: #0876bb;
  padding: 4px;
}

#logout-button.hidden {
  display: none;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; }
.topbar p, .muted, small { color: var(--muted); }

.content {
  padding: 22px;
  display: grid;
  gap: 16px;
}

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

.stat, .panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat { padding: 15px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 8px; font-size: 24px; }

.panel { padding: 16px; overflow: hidden; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.notification-wrap {
  position: relative;
}

.notification-btn {
  position: relative;
  font-size: 18px;
}

.notification-count {
  position: absolute;
  right: -5px;
  top: -7px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.notification-panel {
  position: absolute;
  right: 0;
  top: 46px;
  width: min(420px, calc(100vw - 28px));
  max-height: 70vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 22px 50px rgba(18, 35, 50, 0.22);
  z-index: 20;
}

.notification-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.notification-head small {
  display: block;
  margin-top: 3px;
}

.notification-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.notification-item {
  border: 1px solid #f2b5ad;
  background: #fde8e5;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 4px;
}

.notification-item span,
.notification-item small {
  color: var(--muted);
}

.notification-empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.btn, .chip, .icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  height: 38px;
  padding: 0 12px;
  border-radius: 7px;
  cursor: pointer;
}

.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.icon-btn { width: 38px; padding: 0; font-size: 22px; }
.chip.active { border-color: var(--blue); color: var(--blue); background: #e8f2fb; }

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr.fiado-due td {
  background: #fde8e5;
  border-bottom-color: #f2b5ad;
}

tr.fiado-ok td {
  background: #e7f5ef;
  border-bottom-color: #b8dfcc;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.open { color: var(--amber); background: #fff3dd; }
.badge.done { color: var(--green); background: #e7f5ef; }
.badge.store { color: var(--blue); background: #e8f2fb; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.card {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.card-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.catalog-search {
  max-width: 360px;
}

.tire-cards {
  margin-top: 12px;
}

.tire-card strong {
  font-size: 20px;
}

.tire-tools {
  margin-top: 12px;
}

.tire-photo {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #edf2f6;
}

.tire-photo-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.tire-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.tire-meta strong {
  color: var(--ink);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 26, 0.52);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}

.modal.hidden, .hidden { display: none; }

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #101923;
  display: grid;
  place-items: center;
  padding: 18px;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(390px, 100%);
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
  display: grid;
  gap: 14px;
}

.auth-card img {
  width: 220px;
  max-width: 100%;
  justify-self: center;
  border-radius: 8px;
  background: #0876bb;
  padding: 4px;
}

.auth-card p,
#auth-message {
  color: var(--muted);
}

.modal-panel {
  width: min(900px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.modal-head {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  outline-color: var(--blue);
  background: #fff;
}

textarea { min-height: 92px; resize: vertical; }
.full { grid-column: 1 / -1; }

.service-editor {
  display: grid;
  gap: 10px;
}

.service-editor-head,
.service-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.service-row,
.part-row,
.fiado-service-row,
.fiado-part-row {
  grid-template-columns: 1fr 160px 42px;
}

.fiado-service-row,
.fiado-part-row {
  display: grid;
  gap: 10px;
  align-items: end;
}

.part-row {
  display: grid;
  grid-template-columns: 1fr 150px 145px 42px;
  gap: 10px;
  align-items: end;
}

.service-row button,
.part-row button,
.fiado-service-row button,
.fiado-part-row button {
  width: 42px;
  padding: 0;
}

.modal-actions {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    padding-bottom: 70px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 10;
    height: 66px;
    padding: 6px;
  }

  .brand { display: none; }
  .topbar-logo { width: 128px; height: 44px; }
  nav {
    grid-auto-flow: column;
    grid-auto-columns: minmax(92px, 1fr);
    overflow-x: auto;
  }

  nav button { text-align: center; font-size: 12px; padding: 8px; }
  .stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 650px) {
  .topbar { position: static; flex-direction: column; align-items: stretch; padding: 16px; }
  .content { padding: 16px; }
  .form-grid, .stats { grid-template-columns: 1fr; }
  .service-editor-head,
  .service-row,
  .part-row,
  .fiado-service-row,
  .fiado-part-row { grid-template-columns: 1fr; }
  .service-row button,
  .part-row button,
  .fiado-service-row button,
  .fiado-part-row button { width: 100%; }
  table { min-width: 760px; }
  .table-wrap { overflow-x: auto; }
}
