:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --sidebar: #0f1c33;
  --sidebar-2: #162744;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --red: #c41e2a;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Manrope, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

/* ——— App shell ——— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--sidebar) 0%, #0b1528 100%);
  color: #e8eef8;
  padding: 1.1rem 0.85rem;
  z-index: 50;
}
.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0.55rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 0.75rem;
}
.sidebar-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: block;
  object-fit: cover;
  background: #0f172a;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .35);
}
.auth-wrap .brand-icon {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 0.85rem;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .18);
}
.sidebar-brand strong { display: block; font-size: 0.98rem; }
.sidebar-brand small { display: block; color: #94a3b8; font-size: 0.75rem; margin-top: 0.1rem; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  overflow-y: auto;
  padding: 0 0.25rem;
}
.nav-label {
  margin: 0.85rem 0.55rem 0.35rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7c8aa5;
  font-weight: 700;
}
.sidebar-nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  min-height: 42px;
  display: flex;
  align-items: center;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar-nav a.active {
  background: rgba(37, 99, 235, 0.28);
  color: #fff;
  box-shadow: inset 3px 0 0 #60a5fa;
}

.sidebar-foot {
  margin-top: auto;
  padding: 0.85rem 0.45rem 0.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: grid;
  gap: 0.55rem;
}
.user-chip {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(255,255,255,.05);
}
.user-chip span { display: block; font-weight: 700; font-size: 0.9rem; }
.user-chip small { color: #94a3b8; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .04em; }
.logout-link {
  color: #fda4af !important;
  text-decoration: none;
  font-weight: 700;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.logout-link:hover { background: rgba(220,38,38,.15); text-decoration: none; }

.app-main { min-width: 0; display: flex; flex-direction: column; }
.app-top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.25rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-top-title { flex: 1; min-width: 0; }
.app-top-title h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 800;
}
.app-top-title p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.top-site-link { white-space: nowrap; }
.app-top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}
.btn-logout {
  background: #fff1f2 !important;
  border-color: #fecdd3 !important;
  color: #be123c !important;
  white-space: nowrap;
}
.btn-logout:hover {
  background: #ffe4e6 !important;
  border-color: #fda4af !important;
}

.nav-burger {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  place-items: center;
  gap: 5px;
  padding: 10px;
  flex-shrink: 0;
}
.nav-burger span {
  display: block;
  width: 18px;
  height: 2px;
  background: #1e293b;
  border-radius: 2px;
}
.nav-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 40;
}

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
  flex: 1;
}
.container > h1 { display: none; } /* title is in app-top */

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1rem 1.25rem 1.4rem;
}

/* ——— Auth / login ——— */
.auth-body {
  background:
    radial-gradient(ellipse 60% 40% at 10% 0%, rgba(37,99,235,.12), transparent 55%),
    radial-gradient(ellipse 50% 35% at 90% 10%, rgba(196,30,42,.08), transparent 50%),
    var(--bg);
}
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}
.auth-wrap .login-box {
  width: min(100%, 420px);
  margin: 0;
}
.auth-wrap > p { width: min(100%, 420px); margin: 0 0 0.75rem; }

/* ——— Components ——— */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.flash-ok { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 .85rem; font-size: 1.05rem; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
.section-title {
  margin: 1.25rem 0 0.75rem;
  font-size: 1.05rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar form,
.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex: 1 1 240px;
  align-items: center;
}
.summary-line { margin: 0 0 0.85rem; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=date],
textarea, select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  width: 100%;
  max-width: 100%;
  background: #fff;
  color: var(--text);
  min-height: 42px;
}
.filter-form input[type=text] { flex: 1 1 180px; min-width: 140px; max-width: 320px; }
.filter-form input[type=date],
.filter-form select { flex: 0 1 160px; max-width: 180px; }
textarea { min-height: 80px; }
.chk-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn, button, input[type=submit] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.95rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 42px;
  text-decoration: none;
  box-shadow: 0 8px 16px rgba(29, 78, 216, 0.18);
}
.btn:hover, button:hover { text-decoration: none; filter: brightness(1.05); }
.btn-secondary {
  background: #fff;
  color: #1e293b;
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn-danger { background: var(--danger); box-shadow: none; }
.btn-ok { background: var(--ok); box-shadow: none; }
.btn-sm { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.88rem; }
.btn-link {
  background: transparent;
  color: var(--blue);
  padding: 0.35rem 0.45rem;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  min-height: 36px;
  box-shadow: none;
}
.inline-form { display: inline; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
  border: none;
  min-width: 720px;
}
.responsive-table { min-width: 860px; }
th, td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  background: #f8fafc;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  font-weight: 700;
}
tr:last-child td { border-bottom: none; }
tr.missed { background: #fff7ed; }
tr.delivered { background: #ecfdf5; }
.col-items { max-width: 220px; word-break: break-word; }
.col-actions {
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  align-items: center;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-missed { background: #ffedd5; color: #9a3412; }
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-done { background: #d1fae5; color: #065f46; }
.badge-onway { background: #e0e7ff; color: #3730a3; }
.badge-courier { background: #ede9fe; color: #5b21b6; }
.badge-pay-unpaid { background: #fee2e2; color: #991b1b; }
.badge-pay-partial { background: #fef3c7; color: #92400e; }
.badge-pay-paid { background: #d1fae5; color: #065f46; }
.badge-channel-mobile { background: #ccfbf1; color: #0f766e; }
.badge-channel-landline { background: #e2e8f0; color: #334155; }
.badge-channel-web { background: #ede9fe; color: #5b21b6; }
.badge-channel-whatsapp { background: #dcfce7; color: #166534; }

.durum-stack { display: flex; flex-direction: column; gap: 0.35rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}
.stat-grid .muted { font-size: 0.8rem; margin-bottom: 0.2rem; }

.login-box { max-width: 400px; margin: 3rem auto; }
.form-row { margin-bottom: 0.85rem; }
.form-row label { display: block; font-weight: 700; margin-bottom: 0.25rem; color: #334155; }
.muted { color: var(--muted); font-size: 0.9rem; }
.product-pick {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.product-pick label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
}
.product-pick input[type=number] { width: 72px; max-width: 72px; flex-shrink: 0; }
.code {
  font-family: ui-monospace, Consolas, monospace;
  color: #b45309;
  word-break: break-all;
  font-size: .85rem;
}
.token-box {
  background: #f8fafc;
  border: 1px dashed #94a3b8;
  border-radius: 10px;
  padding: .75rem;
  margin: .5rem 0;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, 280px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 12px 0 40px rgba(0,0,0,.25);
  }
  .nav-toggle:checked ~ .app-shell .sidebar { transform: translateX(0); }
  .nav-toggle:checked ~ .nav-scrim { display: block; }
  .nav-burger { display: grid; }
  .grid-2 { grid-template-columns: 1fr; }
  table, .responsive-table { min-width: 640px; }
}

@media (max-width: 720px) {
  .container { padding: 1rem; }
  .app-top { padding: 0.75rem 0.9rem; }
  .top-site-link { display: none; }
  .filter-form input[type=text],
  .filter-form input[type=date],
  .filter-form select { flex: 1 1 100%; max-width: none; }
  table, .responsive-table { min-width: 0; }
  .responsive-table thead { display: none; }
  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table tr {
    padding: 0.85rem;
    border-bottom: 1px solid var(--line);
  }
  .responsive-table tr:last-child { border-bottom: none; }
  .responsive-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border-bottom: none;
  }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    flex: 0 0 38%;
  }
  .responsive-table td.col-actions {
    justify-content: flex-start;
    padding-top: 0.55rem;
  }
  .responsive-table td.col-actions::before { display: none; }
  .col-items { max-width: none; }
}

@media (max-width: 480px) {
  .toolbar .btn, .toolbar a.btn { flex: 1 1 auto; }
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f8fafc; }
.call-modal[hidden] { display: none !important; }
.call-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.call-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .55);
}
.call-modal-card {
  position: relative;
  width: min(100%, 380px);
  background: #0f172a;
  color: #f8fafc;
  border-radius: 16px;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.call-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}
.call-modal-head .btn-link { color: #cbd5e1; font-size: 1.4rem; line-height: 1; }
.call-modal-phone {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: .04em;
  margin: .75rem 0 .25rem;
}
.call-modal-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.company-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.company-hero-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.action-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.company-create-card summary,
details summary {
  cursor: pointer;
  list-style: none;
}
.company-create-card summary::-webkit-details-marker,
details summary::-webkit-details-marker { display: none; }
.company-create-card summary::after,
details.company-create-card summary::after,
.card > details > summary::after {
  content: ' +';
  float: right;
  color: var(--muted);
}
.company-create-card[open] summary::after,
.card > details[open] > summary::after { content: ' −'; }

tr.service-active { background: #ecfdf5; }
tr.service-closed { background: #f1f5f9; color: #475569; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
