/* ============================================================
   admin_tpp_app — mobile-first stylesheet
   TPP navy / gold identity
   ============================================================ */
:root {
  --navy:       #1B2A6B;
  --navy-dark:  #0f1a47;
  --navy-light: #253580;
  --gold:       #C9A227;
  --gold-dark:  #a8851e;
  --gold-light: #e8c14a;
  --white:      #fff;
  --off-white:  #f8f9fa;
  --light-gray: #f0f2f5;
  --mid-gray:   #6c757d;
  --dark-gray:  #2d3748;
  --text:       #1a202c;
  --border:     #e2e8f0;
  --success:    #38a169;
  --danger:     #e53e3e;
  --warning:    #d69e2e;
  --info:       #3182ce;
  --radius:     10px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
  --topbar-h:   56px;
  --bottomnav-h:64px;
  --sidebar-w:  240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--light-gray);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }

/* ── Brand chip ──────────────────────────────────────────── */
.brand-chip {
  background: var(--gold);
  color: var(--navy-dark);
  font-weight: 800;
  font-size: .95rem;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 1px;
  line-height: 1.4;
}

/* ══════════════════════════════════════════════════════════
   MOBILE LAYOUT  (default — no sidebar)
   ══════════════════════════════════════════════════════════ */

/* Fixed top bar */
.mobile-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--navy-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
  gap: 10px;
}
.mobile-topbar .page-title {
  flex: 1;
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-topbar .topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .8rem;
  overflow: hidden; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.2);
}
.mobile-topbar .topbar-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

/* Sidebar hidden on mobile */
.admin-sidebar { display: none; }

/* Main content area */
.admin-main {
  padding-top: var(--topbar-h);
  padding-bottom: var(--bottomnav-h);
  min-height: 100vh;
}
.admin-content {
  padding: 16px;
  max-width: 1280px;
  width: 100%;
}

/* Flash messages inside content */
.admin-topbar { display: none; } /* desktop only */

/* ── Bottom navigation ───────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: var(--navy-dark);
  display: flex;
  align-items: stretch;
  z-index: 50;
  border-top: 1px solid rgba(255,255,255,.1);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a,
.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: rgba(255,255,255,.55);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .01em;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  padding: 8px 4px 6px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav a i,
.bottom-nav button i { font-size: 1.2rem; }
.bottom-nav a.active,
.bottom-nav a:hover,
.bottom-nav button:hover { color: var(--gold); }
.bottom-nav a.active i { color: var(--gold); }

/* ── "More" overlay & sheet ─────────────────────────────── */
.more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: flex-end;
}
.more-overlay.open { display: flex; }

.more-sheet {
  width: 100%;
  background: var(--navy-dark);
  border-radius: 20px 20px 0 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
  max-height: 80vh;
  overflow-y: auto;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.more-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.more-sheet-header span {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
}
.more-sheet-header button {
  background: none; border: none; color: rgba(255,255,255,.5);
  font-size: 1.4rem; cursor: pointer; line-height: 1; padding: 2px 6px;
}
.more-sheet nav {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}
.more-sheet nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  color: rgba(255,255,255,.8);
  font-weight: 500;
  font-size: .95rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
  transition: background .15s;
}
.more-sheet nav a i { width: 20px; text-align: center; font-size: 1rem; color: rgba(255,255,255,.45); }
.more-sheet nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.more-sheet nav a.active { color: var(--gold); }
.more-sheet nav a.active i { color: var(--gold); }
.more-sheet nav .sheet-sep {
  border-top: 1px solid rgba(255,255,255,.1);
  margin: 6px 0;
}
.more-sheet nav .sheet-label {
  color: rgba(255,255,255,.3);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 10px 22px 4px;
}

/* ══════════════════════════════════════════════════════════
   DESKTOP LAYOUT  ≥ 768px
   ══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  /* Show sidebar, hide mobile chrome */
  .mobile-topbar  { display: none; }
  .bottom-nav     { display: none; }
  .more-overlay   { display: none !important; }

  .admin-sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    background: var(--navy-dark);
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 30;
    overflow-y: auto;
  }

  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
  }
  .sidebar-brand .brand-info { line-height: 1.25; }
  .sidebar-brand .brand-name { color: #fff; font-weight: 700; font-size: .88rem; }
  .sidebar-brand .brand-sub  { color: rgba(255,255,255,.4); font-size: .68rem; }

  .admin-nav {
    display: flex;
    flex-direction: column;
    padding: 10px 8px;
    gap: 1px;
    flex: 1;
  }
  .admin-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255,255,255,.65);
    font-weight: 500;
    font-size: .87rem;
    transition: .15s;
  }
  .admin-nav a i { width: 18px; text-align: center; font-size: .9rem; }
  .admin-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
  .admin-nav a.active { background: var(--gold); color: var(--navy-dark); font-weight: 700; }
  .admin-nav a.active i { color: var(--navy-dark); }
  .admin-nav .nav-sep   { border-top: 1px solid rgba(255,255,255,.08); margin: 8px 4px; }
  .admin-nav .nav-label {
    color: rgba(255,255,255,.3);
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 8px 12px 2px;
  }
  .sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255,255,255,.7);
    font-size: .82rem;
  }
  .sidebar-user .su-name { font-weight: 600; color: #fff; font-size: .84rem; }
  .sidebar-user .su-role { color: rgba(255,255,255,.4); font-size: .72rem; }

  .admin-main {
    margin-left: var(--sidebar-w);
    padding-top: 0;
    padding-bottom: 0;
  }

  .admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 12px;
  }
  .topbar-left h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--navy);
  }
  .topbar-left p {
    font-size: .78rem;
    color: var(--mid-gray);
    margin-top: 1px;
  }
  .topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .topbar-search {
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--off-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 12px;
  }
  .topbar-search i    { color: var(--mid-gray); font-size: .8rem; }
  .topbar-search input {
    border: none; background: transparent; outline: none;
    font-family: inherit; font-size: .84rem; width: 160px; color: var(--text);
  }

  .admin-content {
    padding: 24px;
  }
}

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem;
  overflow: hidden; flex-shrink: 0;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.5rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad  { padding: 16px; }
.card-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-head h2 { font-size: .95rem; color: var(--navy); font-weight: 700; }

@media (min-width: 768px) {
  .card-pad  { padding: 20px; }
  .card-head { padding: 14px 20px; }
}

/* ── Grid ────────────────────────────────────────────────── */
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.grid-5 { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 600px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .grid { gap: 18px; }
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-5 { grid-template-columns: repeat(5, 1fr); }
}

/* ── Stat cards ──────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card .ic {
  position: absolute; right: 12px; top: 12px;
  font-size: 1.4rem; color: var(--light-gray);
}
.stat-card .val {
  font-size: 1.6rem; font-weight: 800;
  color: var(--navy); line-height: 1.1;
}
.stat-card .lbl { color: var(--mid-gray); font-size: .78rem; margin-top: 3px; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data  { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th {
  text-align: left; padding: 10px 12px;
  background: var(--off-white);
  color: var(--mid-gray); font-weight: 600;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafbfc; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px;
  border-radius: 999px; font-size: .71rem; font-weight: 700;
}
.badge-gold    { background: #fdf3d4; color: var(--gold-dark); }
.badge-muted   { background: #edf0f4; color: var(--mid-gray); }
.badge-success { background: #e6f5ec; color: var(--success); }
.badge-warning { background: #fdf1d9; color: var(--warning); }
.badge-danger  { background: #fde8e8; color: var(--danger); }
.badge-info    { background: #e6f0fb; color: var(--info); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600; font-size: .86rem;
  border: 1px solid transparent;
  cursor: pointer; transition: .15s;
  font-family: inherit; white-space: nowrap;
}
.btn-navy    { background: var(--navy);   color: #fff; }
.btn-navy:hover { background: var(--navy-light); }
.btn-gold    { background: var(--gold);   color: var(--navy-dark); }
.btn-gold:hover { background: var(--gold-dark); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--dark-gray); }
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-danger  { background: #fff; border-color: #f1c0c0; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm  { padding: 6px 11px; font-size: .78rem; }
.btn-lg  { padding: 12px 22px; font-size: .95rem; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-weight: 600;
  font-size: .8rem; color: var(--dark-gray); margin-bottom: 5px;
}
.form-control {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; font-family: inherit;
  background: #fff; transition: .15s;
}
.form-control:focus {
  outline: none; border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(27,42,107,.1);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 160px; }
.form-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 14px;
  font-size: .86rem; display: flex; align-items: flex-start; gap: 9px;
}
.alert-success { background: #e6f5ec; color: #1f6b3b; border: 1px solid #b7e0c6; }
.alert-danger  { background: #fde8e8; color: #9b2c2c; border: 1px solid #f3b9b9; }
.alert-warning { background: #fdf1d9; color: #8a6116; border: 1px solid #f0d79a; }

/* ── Misc utilities ──────────────────────────────────────── */
.muted   { color: var(--mid-gray); }
.flex    { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.mt      { margin-top: 16px; }
.mb      { margin-bottom: 16px; }
.tag {
  display: inline-block; background: var(--light-gray);
  color: var(--dark-gray); padding: 2px 8px;
  border-radius: 6px; font-size: .73rem; font-weight: 600;
}
.empty {
  text-align: center; padding: 40px 20px; color: var(--mid-gray);
}
.empty i {
  font-size: 2rem; color: var(--border);
  margin-bottom: 10px; display: block;
}
.hidden { display: none !important; }
code { background: var(--light-gray); padding: 2px 7px; border-radius: 5px; font-size: .82rem; }

/* ── Tenure pill ─────────────────────────────────────────── */
.tenure-pill {
  display: inline-block; background: #eef3f7; color: var(--navy);
  font-weight: 700; padding: 3px 9px; border-radius: 999px; font-size: .76rem;
}

/* ── Signature pad ───────────────────────────────────────── */
.sig-pad-wrap {
  border: 1px dashed var(--navy); border-radius: 8px;
  background: #fff; position: relative;
}
.sig-pad {
  width: 100%; height: 150px; display: block;
  touch-action: none; cursor: crosshair; border-radius: 8px;
}
.sig-pad-hint {
  position: absolute; bottom: 8px; left: 0; right: 0;
  text-align: center; color: #cbd5e0;
  font-size: .78rem; pointer-events: none;
}
.sig-preview {
  max-width: 240px; max-height: 100px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; padding: 5px;
}

/* ── Document viewer ─────────────────────────────────────── */
.doc-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.doc-img   { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; }
.signed-stamp {
  border: 2px solid var(--success); border-radius: 10px;
  padding: 12px 16px; display: inline-block; background: #f3fbf6;
}

/* ── In-place signing editor ─────────────────────────────── */
.signer-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
#pages {
  display: flex; flex-direction: column; gap: 16px;
  align-items: center; background: #e9edf2;
  padding: 12px; border-radius: 8px; max-height: 72vh; overflow: auto;
}
.pg { position: relative; box-shadow: var(--shadow); background: #fff; max-width: 100%; line-height: 0; }
.pg-canvas   { display: block; width: 100%; height: auto; }
.place {
  position: absolute; left: 30%; top: 40%; width: 24%;
  border: 1px dashed transparent; box-sizing: border-box;
}
.place:hover, .place.sel { border-color: var(--navy); }
.place-sig  { width: 100%; display: block; pointer-events: none; }
.place-text {
  min-width: 50px; outline: none; color: #0f1a47;
  font-weight: 600; line-height: 1.1; padding: 1px 2px; white-space: pre-wrap;
}
.place-move {
  position: absolute; top: -20px; left: 0;
  background: var(--navy); color: #fff;
  font-size: .65rem; padding: 1px 6px; border-radius: 4px;
  cursor: move; user-select: none; line-height: 1.3;
}
.place-del {
  position: absolute; top: -20px; right: 0;
  background: var(--danger); color: #fff;
  font-size: .65rem; padding: 1px 6px; border-radius: 4px;
  cursor: pointer; user-select: none; line-height: 1.3;
}
.place-resize {
  position: absolute; right: -7px; bottom: -7px;
  width: 14px; height: 14px; background: var(--gold);
  border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize;
}
.place-copy {
  position: absolute; top: -20px; right: 24px;
  background: var(--gold-dark); color: #fff;
  font-size: .65rem; padding: 1px 6px; border-radius: 4px;
  cursor: pointer; user-select: none; line-height: 1.3;
}
.pg .pg-num {
  position: absolute; top: 4px; left: 4px;
  background: rgba(15,26,71,.72); color: #fff;
  font-size: .65rem; padding: 1px 7px; border-radius: 4px;
  pointer-events: none; line-height: 1.4;
}
