:root {
  --navy: #0b1f3a;
  --navy-2: #132a4d;
  --yellow: #f5c518;
  --yellow-ink: #3a2d00;
  --green: #1b8a3a;
  --green-bg: #e5f6ea;
  --red: #c62828;
  --red-bg: #fdecea;
  --ink: #152033;
  --muted: #5b6b80;
  --line: #d7dee8;
  --bg: #eef2f6;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(11, 31, 58, 0.08);
  --radius: 14px;
  --ok: #0e7a3d;
  --warn: #b45309;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}
a { color: #154b9a; }
button, input, select, textarea { font: inherit; }
h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.25; }

.app-header {
  background: linear-gradient(160deg, var(--navy) 0%, #16345f 100%);
  color: #fff;
  padding: 14px 16px 12px;
  position: sticky; top: 0; z-index: 2000;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.app-header .brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.app-header .titles small { display: block; color: #c9d6ea; font-size: 12px; letter-spacing: .02em; }
.app-header h1 { font-size: 17px; font-weight: 700; }
.app-header .userbox { text-align: right; font-size: 12px; color: #d7e2f3; }
.app-header .userbox strong { display: block; color: #fff; }
nav.tabs {
  display: flex; gap: 6px; overflow-x: auto; margin-top: 12px; padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
nav.tabs a, nav.tabs button.linkish {
  color: #d5e0f2; text-decoration: none; background: transparent; border: 0;
  padding: 8px 12px; border-radius: 999px; white-space: nowrap; font-size: 14px;
}
nav.tabs a.active, nav.tabs a:hover { background: rgba(245,197,24,.18); color: var(--yellow); }
.logout { color: #ffd0d0 !important; }

main { padding: 16px; max-width: 1180px; margin: 0 auto; }
.page-title { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.page-title p { margin: 0; color: var(--muted); font-size: 14px; }

.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 800px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .split { grid-template-columns: 1.4fr 1fr; }
}
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; border: 1px solid #edf1f6;
}
.card h3 { font-size: 14px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 750; letter-spacing: -.03em; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.idle { border-left: 5px solid var(--red); }
.kpi.idle .value { color: var(--red); }
.kpi.money .value { color: #8a1c1c; }
.kpi.ok .value { color: var(--green); }

.banner {
  background: #fff6d6; border: 1px solid #efd56a; color: var(--yellow-ink);
  padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px;
}
.banner.danger { background: var(--red-bg); border-color: #f3b4b0; color: #7f1d1d; }
.banner.ok { background: var(--green-bg); border-color: #b7e3c3; color: #14532d; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr.idle-row { background: #fff5f5; }
tr:hover td { background: #f7fafc; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 650;
  background: #e8eef6; color: #274066;
}
.badge.requested { background: #e8eef6; }
.badge.approved { background: #e0f2fe; color: #075985; }
.badge.erection { background: #fef3c7; color: #92400e; }
.badge.green { background: var(--green-bg); color: #14532d; }
.badge.red { background: var(--red-bg); color: #7f1d1d; }
.badge.work_finished { background: #ede9fe; color: #5b21b6; }
.badge.dismantle_requested { background: #ffedd5; color: #9a3412; }
.badge.dismantled { background: #e5e7eb; color: #374151; }
.badge.closed { background: #e5e7eb; color: #6b7280; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.tag { font-weight: 800; letter-spacing: .04em; }
.tag.green { color: var(--green); }
.tag.red { color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--navy); color: #fff; font-weight: 650; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #e6edf6; color: var(--navy); }
.btn.yellow { background: var(--yellow); color: var(--yellow-ink); }
.btn.danger { background: var(--red); color: #fff; }
.btn.success { background: var(--green); }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btn.block { width: 100%; }

.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 650; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.error { color: var(--red); font-size: 14px; margin: 8px 0; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 20% -10%, #1d4e89, var(--navy));
}
.login-card { width: min(420px, 100%); background: #fff; border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow); }
.login-card .mark {
  width: 48px; height: 48px; border-radius: 12px; background: var(--navy); color: var(--yellow);
  display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 12px;
}
.login-card h1 { font-size: 22px; }
.login-card p.lead { color: var(--muted); margin: 0 0 18px; }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 14px; }
.meta dt { color: var(--muted); font-size: 12px; }
.meta dd { margin: 0; font-weight: 600; }
.section { margin-top: 16px; }

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

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input, .toolbar select { min-width: 140px; flex: 1; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.history time { color: var(--muted); font-size: 12px; display: block; }

.print-sheet { background: #fff; color: #000; padding: 24px; max-width: 420px; margin: 0 auto; }
.print-sheet .id { font-size: 32px; font-weight: 800; letter-spacing: .04em; }
#qrcode { display: flex; justify-content: center; margin: 16px 0; }
@media print {
  .app-header, .no-print { display: none !important; }
  body, main { background: #fff; padding: 0; }
}

.muted { color: var(--muted); }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; }

/* Maps */
.mini-map, .map-full {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #d9e2ec;
  z-index: 1;
}
.mini-map { height: 240px; }
.map-full { height: min(70vh, 640px); min-height: 360px; }
.map-card { padding: 0; overflow: hidden; }
.map-card .map-full { border-radius: 14px; }
.location-box { margin-top: 4px; }
.location-box .mini-map { margin-bottom: 8px; }
.scf-marker { background: none !important; border: 0 !important; }
.scf-pin {
  display: block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.4);
}
.map-legend {
  display: flex; flex-wrap: wrap; gap: 10px 16px;
  margin-top: 10px; font-size: 13px; color: var(--muted); align-items: center;
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend i {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25);
}
.leaflet-container { font-family: inherit; z-index: 1; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.4; }
.leaflet-popup-content .help { margin-top: 2px; }
@media (max-width: 699px) {
  .mini-map { height: 220px; }
  .map-full { height: 60vh; min-height: 300px; }
}
