:root{
  /* Light defaults */
  --bg:#f6f7fb;
  --panel:#ffffff;
  --panel2:#f1f5f9;
  --ink:#0f172a;
  --muted:rgba(15,23,42,.62);
  --border:rgba(15,23,42,.12);
  --line:rgba(15,23,42,.12);
  --primary:#2563eb;
  --ok:#16a34a;
  --warn:#d97706;
  --danger:#b91c1c;
  --radius:14px;
  --tap:44px;
  --text-sm:13px;

  /* glass surfaces */
  --nav-grad1: rgba(255,255,255,.78);
  --nav-grad2: rgba(255,255,255,.56);
  --surface: rgba(255,255,255,.70);
  --surface2: rgba(255,255,255,.55);
  --surface3: rgba(255,255,255,.82);
  --toastbg: rgba(255,255,255,.88);
  --shadow: 0 12px 30px rgba(15,23,42,.10);
  --glow: 0 0 0 6px rgba(37,99,235,.12);
}

/* Explicit dark */
html[data-theme="dark"]{
  --bg:#0b1220;
  --panel:#0f172a;
  --panel2:#111827;
  --ink:#e5e7eb;
  --muted:#94a3b8;
  --border:#1f2a3a;
  --line:#1f2a3a;
  --primary:#60a5fa;
  --ok:#22c55e;
  --warn:#f59e0b;
  --danger:#ef4444;

  --nav-grad1: rgba(15,23,42,.72);
  --nav-grad2: rgba(2,6,23,.62);
  --surface: rgba(15,23,42,.55);
  --surface2: rgba(2,6,23,.25);
  --surface3: rgba(2,6,23,.35);
  --toastbg: rgba(2,6,23,.80);
  --shadow: 0 12px 30px rgba(0,0,0,.25);
  --glow: 0 0 0 6px rgba(96,165,250,.12);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--ink);
  overflow-x:hidden;
}

/* ==========================================================
   Client portal layout (client.php + login.php)
   ========================================================== */
.topbar{
  position:sticky;
  top:0;
  z-index:20;
  background:linear-gradient(180deg, var(--nav-grad1), var(--nav-grad2));
  border-bottom:1px solid var(--border);
  backdrop-filter: blur(10px);
}
.topbar-inner{
  max-width:1200px;
  margin:0 auto;
  padding:14px 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  flex-wrap:wrap;
}
.topbar .brand{
  padding:0;
  border:0;
  background:transparent;
  gap:8px;
}
.topbar .title{ font-size:18px; font-weight:900; }
.topbar .meta{ font-size:12px; color:var(--muted); margin-top:2px; }

.theme-select{
  border:1px solid var(--border);
  background:var(--surface2);
  color:var(--ink);
  border-radius:999px;
  padding:10px 12px;
  min-height:var(--tap);
  font:inherit;
}

.page{
  max-width:1200px;
  margin:0 auto;
  padding:24px 18px 60px;
}
.hero{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:18px;
  margin-bottom:18px;
}
.hero-row{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  flex-wrap:wrap;
}
.hero h1{ margin:0 0 6px 0; font-size:24px; }
.hero p{ margin:0; color:var(--muted); }

.chips{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.chip.ok{
  border-color:color-mix(in srgb, var(--ok) 60%, var(--border));
  background:color-mix(in srgb, var(--ok) 14%, transparent);
  color:color-mix(in srgb, var(--ok) 70%, var(--ink));
  font-weight:700;
}
.chip.warn{
  border-color:color-mix(in srgb, var(--warn) 60%, var(--border));
  background:color-mix(in srgb, var(--warn) 14%, transparent);
  color:color-mix(in srgb, var(--warn) 70%, var(--ink));
  font-weight:700;
}

.grid{
  display:grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap:18px;
}

.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:18px;
}
.card h2{ margin:0 0 12px 0; font-size:18px; }

.tiles{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap:12px;
}
.tile{
  border:1px solid var(--border);
  background:var(--surface2);
  border-radius:14px;
  padding:14px;
}
.tile-title{ margin:0 0 8px 0; font-weight:800; }
.badge{
  display:inline-flex;
  align-items:center;
  border:1px solid var(--border);
  background:var(--surface3);
  border-radius:999px;
  padding:3px 8px;
  font-size:11px;
  margin-left:8px;
  color:var(--muted);
}
.tile-desc{ color:var(--muted); font-size:13px; }
.tile-actions{
  margin-top:12px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.site-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap:10px;
  margin-top:12px;
}

.list{
  list-style:none;
  padding:0;
  margin:0;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.list a{ color:var(--primary); text-decoration:none; }
.list a:hover{ text-decoration:underline; }

.helper{
  margin-top:14px;
  color:var(--muted);
  font-size:13px;
}

@media (max-width: 900px){
  .grid{ grid-template-columns:1fr; }
}

/* soft animated backdrop */
body::before, body::after{
  content:"";
  position:fixed;
  inset:-20vmax;
  z-index:-1;
  background:
    radial-gradient(closest-side, rgba(96,165,250,.22), transparent 55%),
    radial-gradient(closest-side, rgba(34,197,94,.12), transparent 55%),
    radial-gradient(closest-side, rgba(239,68,68,.10), transparent 55%);
  filter: blur(28px);
  transform: translate3d(0,0,0);
  animation: drift 18s ease-in-out infinite;
}
body::after{ animation-duration: 26s; opacity:.65; }
@keyframes drift{ 0%{transform:translate(-1%, -2%) scale(1)} 50%{transform:translate(2%, 1%) scale(1.04)} 100%{transform:translate(-1%, -2%) scale(1)} }

.app{
  display:grid;
  grid-template-columns: 280px 1fr;
  min-height:100vh;
}

.nav{
  border-right:1px solid var(--border);
  background:linear-gradient(180deg, var(--nav-grad1), var(--nav-grad2));
  backdrop-filter: blur(10px);
  padding:16px;
  position:sticky;
  top:0;
  height:100vh;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.brand{
  display:flex;
  gap:12px;
  align-items:center;
  padding:12px;
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:var(--surface3);
}
.brand .dot{
  width:12px;height:12px;border-radius:999px;background:var(--primary);
  box-shadow:var(--glow);
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse{ 0%,100%{transform:scale(1)} 50%{transform:scale(1.12)} }
.brand .title{font-weight:800}
.brand .sub{color:var(--muted); font-size:12px; margin-top:2px}

.menu{display:flex; flex-direction:column; gap:8px; flex:1; overflow:auto; padding-right:4px}
.tab{
  width:100%;
  padding:12px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--surface2);
  color:var(--ink);
  cursor:pointer;
  text-align:left;
  position:relative;
  overflow:hidden;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.tab:hover{ transform: translateY(-1px); }

/* Desktop hover fill */
@media (hover:hover) and (pointer:fine){
  .tab::before{
    content:"";
    position:absolute;
    inset:0;
    background: linear-gradient(90deg, rgba(96,165,250,.18), rgba(34,197,94,.10));
    transform: scaleX(.06);
    transform-origin: left;
    opacity:0;
    transition: transform .18s ease, opacity .18s ease;
  }
  html[data-theme="dark"] .tab::before{
    background: linear-gradient(90deg, rgba(96,165,250,.16), rgba(34,197,94,.08));
  }
  .tab:hover::before{ transform: scaleX(1); opacity:1; }
  .tab > *{ position:relative; }
}

.tab.active{
  border-color:rgba(96,165,250,.55);
  background:rgba(96,165,250,.12);
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
}

.actions{display:flex; flex-direction:column; gap:8px}
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:var(--tap);
  padding:10px 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--surface2);
  color:var(--ink);
  cursor:pointer;
  user-select:none;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(0px) scale(.98); }
.btn.primary{
  border-color:rgba(96,165,250,.55);
  background:rgba(96,165,250,.18);
}
.btn.danger{border-color:rgba(239,68,68,.5); background:rgba(239,68,68,.12)}

.status{font-size:12px; color:var(--muted); padding:0 6px}
.small{font-size:12px; color:var(--muted); padding:0 6px}

.main{padding:22px; max-width:1200px}
.panel{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:18px;
  box-shadow:var(--shadow);
  opacity:0;
  transform: translateY(6px);
  pointer-events:none;
  max-height:0;
  overflow:hidden;
  transition: opacity .16s ease, transform .16s ease, max-height .2s ease;
}
.panel.active{
  opacity:1;
  transform:none;
  pointer-events:auto;
  max-height: 5000px;
  overflow:visible;
}

h2{margin:0 0 14px 0}
.h3{
  margin:18px 0 10px;
  font-size:14px;
  color:var(--muted);
  font-weight:800;
  letter-spacing:.02em;
}

.pill{
  border:1px solid rgba(96,165,250,.45);
  color:var(--ink);
  background:rgba(96,165,250,.10);
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
}

.grid2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}

@media (max-width: 900px){
  .app{grid-template-columns:1fr}

  /* Off-canvas tabs on mobile */
  .nav{
    position:fixed;
    inset:0 auto 0 0;
    width:min(320px, 92vw);
    height:100vh;
    transform: translateX(-105%);
    transition: transform .18s ease;
    z-index:50;
  }
  body.tabs-open .nav{ transform: translateX(0); }
  body.tabs-hidden-mobile .nav{ display:none; }

  .main{padding:18px; max-width:100%}
  .grid2{grid-template-columns:1fr}
}

.mobileTabsBtn{
  position:fixed;
  left:14px;
  bottom:14px;
  z-index:60;
  min-height:44px;
  padding:10px 14px;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--surface3);
  color:var(--ink);
  box-shadow:var(--shadow);
  display:none;
}
@media (max-width: 900px){
  .mobileTabsBtn{ display:inline-flex; align-items:center; gap:8px; }
  body.tabs-hidden-mobile .mobileTabsBtn{ display:none; }
}

/* Modal (Tab Manager) */
.modal{
  position:fixed;
  inset:0;
  z-index:80;
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  background: rgba(0,0,0,.38);
}
.modal.show{ display:flex; }
.modalCard{
  width:min(720px, 96vw);
  max-height: 86vh;
  overflow:auto;
  background: var(--panel);
  border:1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding:14px;
}
.modalHead{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding:6px 6px 10px; }
.modalHead h3{ margin:0; font-size:16px; }
.tabsList{ display:flex; flex-direction:column; gap:10px; padding:6px; }
.tabRow{
  border:1px solid var(--border);
  background: var(--surface2);
  border-radius: 14px;
  padding:10px;
  display:grid;
  grid-template-columns: 34px 1fr auto;
  gap:10px;
  align-items:center;
}
.tabRow .grab{ width:34px; height:34px; border-radius:12px; display:flex; align-items:center; justify-content:center; border:1px solid var(--border); background:var(--surface3); color:var(--muted); }
.tabRow .meta{ display:flex; flex-direction:column; gap:6px; }
.tabRow input{
  width:100%;
  padding:9px 10px;
  border-radius:12px;
  border:1px solid var(--border);
  background: var(--surface3);
  color: var(--ink);
}
.tabRow .badge{ font-size:12px; color:var(--muted); }
.tabRow .rowBtns{ display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.modalFoot{ display:flex; gap:10px; justify-content:space-between; align-items:center; padding:10px 6px 6px; }
.modalFoot .left{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.switch{ display:flex; align-items:center; gap:10px; color:var(--muted); font-size:13px; }

.field label{display:block; font-weight:700; font-size:13px; margin-bottom:6px}
.field input, .field select, textarea{
  width:100%;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--surface3);
  color:var(--ink);
  outline:none;
}
textarea{resize:vertical; min-height:160px}

.field.check label{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:700;
}

.row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin:0 0 10px 0;
}
.row .grow{flex:1}

.hint{color:var(--muted); font-size:12px; margin-bottom:10px}

.list{display:flex; flex-direction:column; gap:12px}
.item{
  border:1px solid var(--border);
  background:var(--surface2);
  border-radius:16px;
  padding:12px;
  box-shadow: 0 10px 24px rgba(0,0,0,.10);
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.item:hover{ transform: translateY(-1px); }
.item.drag-over{ border-color: rgba(96,165,250,.65); box-shadow: 0 0 0 5px rgba(96,165,250,.14); }
.list.dragging .item{ opacity:.8; }

.itemHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
}
.handle{
  width:36px;height:36px;border-radius:12px;
  display:flex;align-items:center;justify-content:center;
  border:1px solid var(--border);
  background:var(--surface3);
  color:var(--muted);
  cursor:grab;
  user-select:none;
}
.itemActions{display:flex; gap:10px}

.subgrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}
@media (max-width: 900px){
  .subgrid{grid-template-columns:1fr}
}

.chip{
  display:inline-flex;
  align-items:center;
  gap:10px;
  border:1px solid var(--border);
  background:var(--surface3);
  border-radius:999px;
  padding:8px 12px;
  font-size:13px;
  color:var(--muted);
}

.sp{flex:1}

.history{display:flex; flex-direction:column; gap:10px; margin-top:10px}
.histRow{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:12px;
  border:1px solid var(--border);
  background:var(--surface2);
  border-radius:14px;
}
.histRow .d{color:var(--muted); font-size:12px; margin-top:4px}

.photos{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:12px;
}
@media (max-width: 900px){
  .photos{grid-template-columns: repeat(2, 1fr);}
}
.photoCard{
  border:1px solid var(--border);
  background:var(--surface2);
  border-radius:16px;
  overflow:hidden;
  box-shadow: 0 10px 24px rgba(0,0,0,.10);
  transition: transform .12s ease, border-color .12s ease;
}
.photoCard:hover{ transform: translateY(-1px); }
.photoCard.drag-over{ border-color: rgba(96,165,250,.65); box-shadow: 0 0 0 5px rgba(96,165,250,.14); }
.photoTop{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px;
}
.photoCard img{ width:100%; height:180px; object-fit:cover; display:block; background:var(--panel); }
.photoMeta{ padding:10px; display:flex; flex-direction:column; gap:8px; }

/* Toast */
.toast{
  position:fixed;
  left:50%;
  bottom:20px;
  transform: translateX(-50%) translateY(18px);
  background:var(--toastbg);
  border:1px solid var(--border);
  border-radius:999px;
  padding:10px 14px;
  box-shadow: var(--shadow);
  opacity:0;
  pointer-events:none;
  transition: transform .18s ease, opacity .18s ease;
  z-index:100;
  font-size:13px;
}
.toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }
.toast[data-kind="ok"]{ border-color: rgba(34,197,94,.55); }
.toast[data-kind="err"]{ border-color: rgba(239,68,68,.55); }

/* FX layer */
.fx{ position:fixed; inset:0; pointer-events:none; z-index:90; }
.ping{
  position:absolute;
  width:12px; height:12px;
  border-radius:999px;
  border:2px solid rgba(96,165,250,.8);
  transform: translate(-50%,-50%) scale(.6);
  opacity:.9;
  animation: ping .65s ease-out forwards;
}
@keyframes ping{
  to{ transform: translate(-50%,-50%) scale(7); opacity:0; }
}
