/* ============================================================
   Ved Associates - Rent Agreement Management System
   Theme: "Ledger" - inspired by property deed paperwork &
   filing-cabinet organization. Deep ink-green + brass/amber
   accent, slab-serif headings for a "official document" feel.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Zilla+Slab:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #1B2E28;         /* deep forest ink */
  --ink-soft: #2C4038;
  --paper: #F7F4EC;       /* aged paper */
  --paper-alt: #EFEADC;
  --line: #DAD3BE;
  --brass: #B8862E;       /* brass/amber accent */
  --brass-dark: #8F6A22;
  --stamp-red: #A8402F;
  --stamp-green: #3D7A4E;
  --stamp-blue: #35618C;
  --text: #23271F;
  --text-muted: #6B6555;
  --white: #FFFFFF;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(27,46,40,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--paper);
  color: var(--text);
}

h1, h2, h3, h4, .brand, .logo-font {
  font-family: 'Zilla Slab', Georgia, serif;
}

a { color: var(--brass-dark); text-decoration: none; }

/* ---------------- Layout shell ---------------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 62px;
  flex-shrink: 0;
  border-bottom: 3px solid var(--brass);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex: 1;
}
.hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  margin-right: 10px;
}
.hamburger span { width: 22px; height: 2px; background: var(--paper); display: block; }

.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.role-pill {
  background: var(--brass);
  color: var(--ink);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.btn-logout {
  color: var(--paper);
  border: 1px solid rgba(247,244,236,0.35);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.btn-logout:hover { background: rgba(247,244,236,0.1); }

.app-body { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 220px;
  background: var(--ink-soft);
  flex-shrink: 0;
  padding: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #D7DED9;
  padding: 11px 22px;
  font-size: 0.91rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  position: relative;
}
.sidebar a .icon { flex-shrink: 0; opacity: 0.85; }
.sidebar a span:not(.nav-count) { flex: 1; }
.sidebar a:hover { background: rgba(255,255,255,0.05); color: var(--paper); }
.sidebar a:hover .icon { opacity: 1; }
.sidebar a.active {
  background: rgba(184,134,46,0.15);
  border-left-color: var(--brass);
  color: var(--brass);
  font-weight: 600;
}
.sidebar a.active .icon { opacity: 1; }

.content {
  flex: 1;
  padding: 26px 30px 60px;
  min-width: 0;
  overflow-x: auto;
}

/* ---------------- Common components ---------------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 1.6rem; color: var(--ink); }
.page-sub { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }

.btn {
  display: inline-block;
  background: var(--ink);
  color: var(--paper) !important;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: var(--ink-soft); }
.btn:active { transform: scale(0.98); }
.btn-brass { background: var(--brass); color: var(--ink) !important; }
.btn-brass:hover { background: var(--brass-dark); color: var(--paper) !important; }
.btn-outline {
  background: transparent;
  color: var(--ink) !important;
  border: 1.5px solid var(--line);
}
.btn-outline:hover { border-color: var(--ink); }
.btn-danger { background: var(--stamp-red); color: var(--white) !important; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brass);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .num { font-family: 'Zilla Slab', serif; font-size: 2rem; font-weight: 700; color: var(--ink); line-height: 1; }
.stat-card .label { color: var(--text-muted); font-size: 0.82rem; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-card.alert { border-left-color: var(--stamp-red); }
.stat-card.alert .num { color: var(--stamp-red); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table-wrap {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  background: var(--paper-alt);
  color: var(--ink);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}
tbody tr:hover { background: #FBF9F3; }
tbody tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.74rem; font-weight: 700; }
.badge-green { background: #E1F0E4; color: var(--stamp-green); }
.badge-orange { background: #FCEBD5; color: #A05A16; }
.badge-red { background: #F7E1DD; color: var(--stamp-red); }
.badge-gray { background: #E9E7E0; color: var(--text-muted); }
.badge-blue { background: #DEE9F2; color: var(--stamp-blue); }

.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 0.9rem; font-weight: 500; }
.alert-success { background: #E1F0E4; color: var(--stamp-green); border: 1px solid #b8dcc0; }
.alert-error { background: #F7E1DD; color: var(--stamp-red); border: 1px solid #eac1b9; }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
label { font-size: 0.82rem; font-weight: 600; color: var(--ink); }
input, select, textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(184,134,46,0.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.hint { font-size: 0.78rem; color: var(--text-muted); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--ink) 0%, var(--ink-soft) 100%);
  padding: 20px;
}
.login-card {
  background: var(--paper);
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  border-top: 5px solid var(--brass);
}
.login-card h1 { text-align: center; margin: 0 0 4px; color: var(--ink); font-size: 1.5rem; }
.login-card .tagline { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 26px; }
.login-card .btn { width: 100%; margin-top: 8px; }
.login-hint { text-align: center; margin-top: 16px; font-size: 0.78rem; color: var(--text-muted); }
.login-links { text-align: center; margin-top: 14px; font-size: 0.85rem; }
.login-links a { color: var(--brass-dark); font-weight: 600; }
.otp-input {
  font-size: 1.6rem;
  letter-spacing: 0.5em;
  text-align: center;
  font-weight: 700;
  padding: 12px 10px 12px 16px;
}
.otp-resend-form { text-align: center; margin-top: 10px; }
.btn-link {
  background: none; border: none; padding: 4px 6px;
  color: var(--brass-dark); font-weight: 600; font-size: 0.85rem;
  cursor: pointer; text-decoration: underline;
}
.btn-link:hover { color: var(--brass); }
.btn-install {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid rgba(255,255,255,0.4);
  color: var(--paper); border-radius: 8px; padding: 7px 12px;
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.btn-install:hover { background: rgba(247,244,236,0.12); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 10px; }

.section-divider { border: none; border-top: 1px dashed var(--line); margin: 24px 0; }
.wa-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #E1F0E4;
  color: var(--stamp-green) !important;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 600;
}
.wa-link:hover { background: #cbe6d1; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px 24px; }
.detail-item .k { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin-bottom: 3px; }
.detail-item .v { font-size: 0.98rem; font-weight: 600; color: var(--ink); }

/* ---------------- Responsive ---------------- */
@media (max-width: 880px) {
  .hamburger { display: flex; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-user { flex-shrink: 0; gap: 8px; }
  .brand small { display: none; }
  .sidebar {
    position: fixed;
    top: 62px; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 40;
    box-shadow: 4px 0 14px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 18px 14px 50px; }
  .user-name { display: none; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  .table-wrap table tr {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }
  .table-wrap table td {
    border: none;
    white-space: normal;
    padding: 6px 2px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    text-align: right;
  }
  .table-wrap table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    text-align: left;
    font-size: 0.76rem;
    text-transform: uppercase;
  }

  /* Touch-friendly targets + prevent iOS auto-zoom on focus (needs >=16px) */
  input, select, textarea { font-size: 16px; padding: 12px 12px; }
  .btn, button, .btn-logout, .btn-install, .btn-link { min-height: 44px; }
  .sidebar a { padding: 14px 20px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn, .form-actions button { width: 100%; }
  .btn-install span, .btn-install { font-size: 0.75rem; padding: 7px 9px; }
}

@media (max-width: 460px) {
  .login-card { padding: 26px 20px; margin: 0 12px; }
  .otp-input { letter-spacing: 0.35em; font-size: 1.35rem; }
  .topbar { padding: 0 10px; gap: 6px; }
  .brand small { display: none; }
  .role-pill { display: none; }
}

/* ---------------- Professional operations UI ---------------- */
.brand { display:flex; align-items:center; gap:10px; line-height:1.05; min-width:0; overflow:hidden; }
.brand-mark { width:34px; height:34px; flex-shrink:0; display:grid; place-items:center; border:1px solid rgba(255,255,255,.35); border-radius:8px; font:700 13px Inter,sans-serif; color:var(--brass); letter-spacing:.5px; }
.brand > div { min-width:0; overflow:hidden; }
.brand strong { display:block; font:700 1.12rem Inter,sans-serif; letter-spacing:-.2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.brand small { display:block; margin-top:3px; color:#B9C7C0; font:500 .64rem Inter,sans-serif; letter-spacing:.8px; text-transform:uppercase; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.nav-count { display:inline-grid; place-items:center; min-width:20px; height:20px; padding:0 5px; margin-left:6px; border-radius:10px; background:var(--stamp-red); color:#fff; font-size:.68rem; font-weight:700; }
.automation-card { border-top:3px solid var(--brass); }
.section-kicker { font-size:.68rem; font-weight:800; letter-spacing:1.2px; color:var(--brass-dark); margin-bottom:4px; }
.automation-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:10px; }
.toggle-row { display:flex; align-items:center; gap:10px; padding:12px 14px; border:1px solid var(--line); border-radius:8px; background:#FCFBF7; font-size:.86rem; cursor:pointer; }
.toggle-row input { width:18px; height:18px; accent-color:var(--brass-dark); }

/* ---------------- Settings accordion ----------------
   Each settings section is a native <details> element so it works
   without JS at all (progressive enhancement); script.js adds the
   "only one open at a time" accordion behaviour and auto-opens the
   right section when arriving via #anchor (e.g. after a save). */
.settings-accordion { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.settings-section {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.settings-section > summary.settings-section-header {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.settings-section > summary.settings-section-header::-webkit-details-marker { display: none; }
.settings-section > summary.settings-section-header::marker { content: ''; }
.settings-section-header .ssh-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-section-header .ssh-kicker { font-size:.66rem; font-weight:800; letter-spacing:1.1px; color: var(--brass-dark); }
.settings-section-header .ssh-title { font-family: 'Zilla Slab', serif; font-size: 1.08rem; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.settings-section-header .ssh-sub { font-size: .78rem; color: var(--text-muted); font-weight: 400; }
.settings-section-header .ssh-chevron {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: transform .2s ease, background .2s ease, color .2s ease;
}
.settings-section[open] > summary.settings-section-header { border-bottom: 1px solid var(--line); }
.settings-section[open] .ssh-chevron { transform: rotate(180deg); background: var(--brass); color: var(--ink); border-color: var(--brass); }
.settings-section-body { padding: 20px; animation: settingsSectionOpen .18s ease; }
@keyframes settingsSectionOpen { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.settings-section.has-unsaved > summary .ssh-title::after {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--stamp-red);
  display: inline-block;
}
.danger-panel { border-top:3px solid var(--stamp-red); background:#FFF9F7; }
.page-head .badge { vertical-align:middle; margin-left:8px; }
.table-wrap { box-shadow:0 8px 24px rgba(27,46,40,.06); }
.btn { border-radius:8px; }
.btn { display:inline-flex; align-items:center; gap:7px; }
.card { border-radius:10px; }

/* ---------------- Global loading overlay ----------------
   Shown while a form that saves data (add/edit/delete/login/etc.)
   is submitting, so the user gets clear feedback and can't fire off
   a second action (e.g. double-click "Save") while the first one is
   still being processed by the server. */
#globalLoadingOverlay {
  position: fixed; inset: 0; z-index: 5000;
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  background: rgba(20,28,24,.55);
  backdrop-filter: blur(1px);
}
#globalLoadingOverlay.show { display: flex; }
#globalLoadingOverlay .gl-spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(247,244,236,0.35);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: glSpin .8s linear infinite;
}
#globalLoadingOverlay .gl-text {
  color: var(--paper); font-weight: 600; font-size: 0.92rem; letter-spacing: .2px;
}
@keyframes glSpin { to { transform: rotate(360deg); } }

/* ---------------- Agent quick-add + picker ---------------- */
.agent-picker { display:flex; gap:8px; align-items:center; }
.agent-picker select { flex:1; }
.modal-overlay {
  position:fixed; inset:0; background:rgba(20,28,24,.55);
  display:flex; align-items:center; justify-content:center;
  z-index:1000; padding:16px;
}
.modal-box {
  background:#fff; border-radius:10px; padding:22px 24px;
  width:100%; max-width:480px; max-height:90vh; overflow-y:auto;
  box-shadow:0 20px 50px rgba(0,0,0,.25);
}
.modal-box h3 { margin-top:0; margin-bottom:14px; }
.modal-box .form-actions { margin-top:16px; }

.wa-link.btn-disabled { opacity:.5; pointer-events:none; cursor:not-allowed; }

/* Collapsible "Add New ___" form card - collapsed by default,
   revealed by the "+ Add" button in the page header (or forced open
   by the server when editing / after a failed save). */
.collapsible-card { display: none; }
.collapsible-card.open { display: block; animation: fadeInDown .15s ease; }
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* "Add New ___" as a modal popup - hidden by default, shown by
   adding .open (see toggleAddForm() in script.js). Reuses the same
   .modal-box look as the existing Agent quick-add popup. */
.app-modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,28,24,.55);
  align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.app-modal.open { display: flex; animation: fadeInDown .15s ease; }
.app-modal .modal-box { width: 100%; max-width: 640px; }


/* Scrollbar Styling */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}
