/* ── App shell ───────────────────────────────────────────────────────────── */
.t-shell { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.t-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 100;
  background: #fff; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; padding: 0 24px; gap: 14px;
  box-shadow: 0 1px 4px rgba(22,35,66,.06);
}
.t-topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: .95rem; color: #162342; letter-spacing: -.02em;
}
.t-topbar-brand .logo-box {
  width: 32px; height: 32px; background: #162342; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.t-topbar-brand .logo-box span {
  width: 14px; height: 14px; background: #00b4ff; border-radius: 3px; display: block;
}
.t-topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.t-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #e0f2fe;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 800; color: #0369a1; cursor: pointer;
  position: relative; border: 2px solid #bae6fd;
}
.t-dropdown {
  position: absolute; top: 44px; right: 0; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 12px; min-width: 170px;
  box-shadow: 0 12px 32px rgba(0,0,0,.1); display: none; z-index: 200;
  overflow: hidden;
}
.t-dropdown.open { display: block; }
.t-dropdown a {
  display: block; padding: 11px 18px; font-size: .85rem; color: #475569;
  transition: background .15s; font-weight: 500;
}
.t-dropdown a:hover { background: #f8fafc; color: #162342; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.t-sidebar {
  position: fixed; top: 60px; left: 0; bottom: 0; width: 56px; z-index: 90;
  background: #162342;
  display: flex; flex-direction: column; align-items: center; padding-top: 20px; gap: 6px;
  box-shadow: 2px 0 8px rgba(22,35,66,.15);
}
.t-sidebar a {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #4a6080; transition: all .2s;
}
.t-sidebar a:hover { background: rgba(0,180,255,.12); color: #7dd3fc; }
.t-sidebar a.active { background: rgba(0,180,255,.18); color: #00b4ff; }
.t-sidebar svg { width: 20px; height: 20px; }

/* ── Content ─────────────────────────────────────────────────────────────── */
.t-content {
  margin-top: 60px; margin-left: 56px; padding: 24px 40px; min-height: calc(100vh - 60px);
}

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.t-auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.t-auth-card {
  background: #fff; border-radius: 20px; padding: 48px 44px;
  width: 100%; max-width: 420px; border: 1px solid #e2e8f0;
  box-shadow: 0 8px 40px rgba(22,35,66,.08);
}
.t-auth-card h1 {
  font-size: 1.7rem; font-weight: 800; color: #162342;
  letter-spacing: -.04em; margin-bottom: 6px;
}
.t-auth-card .subtitle { font-size: .9rem; color: var(--muted); margin-bottom: 32px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.t-field { margin-bottom: 18px; }
.t-field label {
  display: block; font-size: .72rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: #64748b; margin-bottom: 7px;
}
.t-field input, .t-field textarea, .t-field select {
  width: 100%; padding: 11px 16px; border: 1.5px solid #e2e8f0;
  border-radius: 10px; font-size: .92rem; color: #162342;
  background: #fff; transition: border-color .2s, box-shadow .2s; font-family: inherit;
}
.t-field input:focus, .t-field textarea:focus, .t-field select:focus {
  outline: none; border-color: #00b4ff; box-shadow: 0 0 0 3px rgba(0,180,255,.1);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.t-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px; border-radius: 10px; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: all .2s; border: none; font-family: inherit;
  white-space: nowrap;
}
.t-btn-primary { background: #00b4ff; color: #fff; box-shadow: 0 2px 8px rgba(0,180,255,.3); }
.t-btn-primary:hover { background: #0099dd; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,180,255,.35); }
.t-btn-ghost {
  background: #fff; color: #475569; border: 1.5px solid #e2e8f0;
}
.t-btn-ghost:hover { border-color: #00b4ff; color: #00b4ff; background: #f0f9ff; }
.t-btn-full { width: 100%; }
.t-btn-danger { background: #ef4444; color: #fff; box-shadow: 0 2px 8px rgba(239,68,68,.2); }
.t-btn-danger:hover { background: #dc2626; transform: translateY(-1px); }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.t-alert {
  padding: 13px 18px; border-radius: 10px; font-size: .88rem;
  margin-bottom: 20px; font-weight: 500;
}
.t-alert-error  { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.t-alert-success{ background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ── Stat cards (dashboard) ──────────────────────────────────────────────── */
.t-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 20px; margin-bottom: 40px; }
.t-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 2px 8px rgba(22,35,66,.04);
  transition: box-shadow .2s, transform .2s;
}
.t-card:hover { box-shadow: 0 6px 20px rgba(22,35,66,.08); transform: translateY(-1px); }
.t-card-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: #94a3b8; margin-bottom: 10px;
}
.t-card-value { font-size: 2.4rem; font-weight: 800; color: #162342; letter-spacing: -.04em; line-height: 1; }
.t-card-sub { font-size: .8rem; color: #94a3b8; margin-top: 6px; }

/* ── Parcel cards (dashboard recent) ────────────────────────────────────── */
.t-parcel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.t-parcel-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; overflow: hidden;
  transition: transform .2s, box-shadow .2s; box-shadow: 0 2px 8px rgba(22,35,66,.04);
}
.t-parcel-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(22,35,66,.1); }
.t-parcel-card-thumb {
  height: 260px; background: linear-gradient(135deg,#c8dfc8,#a8c8a8);
  display: flex; align-items: center; justify-content: center;
}
.t-parcel-card-body { padding: 18px 20px; }
.t-parcel-card-name { font-size: .92rem; font-weight: 700; color: #162342; margin-bottom: 5px; }
.t-parcel-card-meta { font-size: .78rem; color: #94a3b8; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.t-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border-radius: 16px; overflow: hidden; border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(22,35,66,.04);
}
.t-table th {
  padding: 14px 20px; text-align: left; font-size: .67rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: #94a3b8;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0;
}
.t-table td { padding: 16px 20px; font-size: .88rem; color: #475569; border-bottom: 1px solid #f1f5f9; }
.t-table tr:last-child td { border-bottom: none; }
.t-table tr:hover td { background: #f8fafc; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.t-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 32px; flex-wrap: wrap; gap: 12px; }
.t-page-title { font-size: 1.75rem; font-weight: 800; color: #162342; letter-spacing: -.04em; }

/* ── Search / text input (standalone) ───────────────────────────────────── */
.t-search {
  padding: 10px 16px; border: 1.5px solid #e2e8f0; border-radius: 10px;
  font-size: .88rem; font-family: inherit; color: #162342;
  transition: border-color .2s, box-shadow .2s;
}
.t-search:focus { outline: none; border-color: #00b4ff; box-shadow: 0 0 0 3px rgba(0,180,255,.1); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.t-toast {
  position: fixed; bottom: 28px; right: 28px; z-index: 9999;
  background: #162342; color: #fff; padding: 14px 22px; border-radius: 12px;
  font-size: .88rem; font-weight: 500; box-shadow: 0 8px 28px rgba(22,35,66,.2);
  transform: translateY(80px); opacity: 0; transition: all .35s cubic-bezier(.16,1,.3,1);
}
.t-toast.show { transform: none; opacity: 1; }

/* ── Mobile nav overlay ──────────────────────────────────────────────────── */
.t-mob-nav-btn {
  display: none; background: none; border: none; cursor: pointer; padding: 4px; color: #162342;
}
.t-mob-nav {
  display: none; position: fixed; inset: 0; background: rgba(22,35,66,.97);
  backdrop-filter: blur(24px); z-index: 400;
  flex-direction: column; align-items: center; justify-content: center; gap: 28px;
}
.t-mob-nav.open { display: flex; }
.t-mob-nav a { font-size: 1.5rem; font-weight: 700; color: #fff; }
.t-mob-nav-close { position: absolute; top: 24px; right: 24px; background: none; border: none; color: #fff; cursor: pointer; font-size: 1.5rem; }

/* ── Map editor ──────────────────────────────────────────────────────────── */
.t-editor-wrap { position: fixed; top: 60px; left: 56px; right: 0; bottom: 0; }
#leaflet-map   { width: 100%; height: 100%; position: relative; z-index: 0; }

.t-editor-toolbar {
  position: absolute; bottom: 20px; right: 16px; z-index: 1100;
  background: #fff; border-radius: 12px; padding: 8px 10px;
  box-shadow: 0 4px 20px rgba(22,35,66,.15);
  display: flex; flex-direction: row; gap: 4px; pointer-events: auto;
}
.t-editor-toolbar button {
  width: 40px; height: 40px; border: none; border-radius: 9px; cursor: pointer;
  background: transparent; color: #94a3b8; transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.t-editor-toolbar button:hover, .t-editor-toolbar button.active {
  background: #e0f2fe; color: #00b4ff;
}
.t-editor-toolbar .sep { width: 1px; height: 24px; background: #f1f5f9; margin: 0 3px; align-self: center; }

.t-basemap-picker {
  position: absolute; bottom: 20px; left: 20px; z-index: 1100;
  background: rgba(255,255,255,.97); border-radius: 10px;
  border: 1px solid #e2e8f0; padding: 8px 16px;
  font-size: .8rem; font-weight: 600; color: #162342; cursor: pointer;
  backdrop-filter: blur(8px); pointer-events: auto;
  box-shadow: 0 4px 16px rgba(22,35,66,.1);
}

.t-metric-card {
  position: absolute; top: 20px; right: 20px; z-index: 1100;
  background: rgba(255,255,255,.98); border: 1px solid #e2e8f0;
  border-radius: 16px; padding: 16px; width: 260px;
  box-shadow: 0 8px 28px rgba(22,35,66,.12); display: none; pointer-events: auto;
}
.t-metric-card.visible { display: block; }
.t-metric-card-title {
  font-size: .62rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: #00b4ff; margin-bottom: 14px;
}
.t-metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.t-metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.t-metric-item { background: #f8fafc; border-radius: 8px; padding: 8px 10px; overflow: hidden; }
.t-metric-item .lbl { font-size: .6rem; color: #94a3b8; margin-bottom: 2px; white-space: nowrap; }
.t-metric-item .val {
  font-size: .85rem; font-weight: 700; color: #162342;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3;
}
.t-metric-item .sub { font-size: .65rem; color: #94a3b8; }

.t-metric-badge {
  display: none; position: absolute; top: 20px; right: 20px; z-index: 1100;
  background: rgba(255,255,255,.97); border-radius: 10px;
  padding: 8px 16px; border: 1px solid #e2e8f0;
  font-size: .85rem; font-weight: 700; color: #162342;
  box-shadow: 0 4px 16px rgba(22,35,66,.1); pointer-events: auto;
}
.t-metric-drawer {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 2000;
  background: #fff; border-radius: 24px 24px 0 0; padding: 24px 24px 36px;
  box-shadow: 0 -8px 40px rgba(22,35,66,.15);
  transform: translateY(100%); transition: transform .35s cubic-bezier(.16,1,.3,1);
}
.t-metric-drawer.open { transform: none; }
.t-drawer-handle {
  width: 44px; height: 4px; background: #e2e8f0; border-radius: 2px; margin: 0 auto 20px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .t-sidebar { display: none; }
  .t-content { margin-left: 0; padding: 20px 16px; }
  .t-editor-wrap { left: 0; }
  .t-mob-nav-btn { display: block; }

  /* Parcel grid: 2 cols on tablet */
  .t-parcel-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }

  /* Page header: stack on small screens */
  .t-page-header { flex-direction: column; align-items: flex-start; }
  .t-page-title { font-size: 1.35rem; }

  /* Portfolio card header buttons: wrap + shrink */
  .t-card [style*="display:flex;gap:6px;align-items:center"] {
    flex-wrap: wrap;
    gap: 4px !important;
  }

  /* Messages modal: single panel on mobile */
  #messagesModal > div { width: 100vw !important; max-width: 100vw !important; height: 100vh !important; border-radius: 0 !important; }
  #msgPanelList { display: none !important; }
  #msgPanelDetail { padding: 14px !important; }

  /* Parcel picker modal */
  #parcelPickerModal > div { width: 100vw !important; max-width: 100vw !important; border-radius: 0 !important; }

  /* Settings tabs: scroll horizontally */
  .adm-wrap { border-radius: 0 !important; }
}

@media (max-width: 480px) {
  .t-metric-card { display: none !important; }
  .t-metric-badge { display: block; }
  .t-metric-drawer { display: block; }

  /* Parcel grid: 1 col on phone */
  .t-parcel-grid { grid-template-columns: 1fr; }

  /* Stat cards: 2 per row minimum */
  .t-card-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
  .t-card { padding: 18px 16px; }
  .t-card-value { font-size: 1.8rem; }

  /* Settings tabs overflow */
  div[style*="border-bottom:2px solid #e2e8f0"] { overflow-x: auto; white-space: nowrap; }
  div[style*="border-bottom:2px solid #e2e8f0"] button { min-width: max-content; }

  /* Admin table: horizontal scroll */
  .adm-table-wrap { overflow-x: auto; }
  .adm-stats { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .adm-filters { flex-direction: column; }
  .adm-search { min-width: unset !important; }
}
