/* ============================================================
   e-Office Lower Chitral — Main Stylesheet
   Design: Deep navy + gold accent, modern government feel
   ============================================================ */

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

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --navy:        #0f1e3c;
  --navy-mid:    #1a2f5a;
  --navy-light:  #243d6e;
  --gold:        #c9a84c;
  --gold-light:  #e8c97a;
  --surface:     #f4f6fb;
  --card:        #ffffff;
  --border:      #e2e8f0;
  --text-main:   #1a2030;
  --text-muted:  #64748b;
  --text-light:  #94a3b8;
  --green:       #16a34a;
  --yellow:      #d97706;
  --red:         #dc2626;
  --blue:        #2563eb;

  --sidebar-w:   260px;
  --header-h:    64px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:   0 4px 24px rgba(0,0,0,.12);
  --transition:  0.18s ease;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: 'Inter', sans-serif; background: var(--surface); color: var(--text-main); line-height: 1.6; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Login Page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, var(--navy-light) 100%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo img {
  height: 64px;
  margin: 0 auto 12px;
}
.login-logo h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
}
.login-logo p {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.login-divider {
  width: 40px;
  height: 3px;
  background: var(--gold);
  border-radius: 2px;
  margin: 12px auto 0;
}

/* ── App Shell ──────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-brand img {
  height: 36px;
  border-radius: 4px;
}
.sidebar-brand-text h2 {
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar-brand-text span {
  font-size: .7rem;
  color: var(--gold-light);
}
.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}
.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 12px 20px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.7);
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(201,168,76,.15);
  color: var(--gold-light);
  border-right: 3px solid var(--gold);
}
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--navy-light);
  border: 2px solid var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--gold-light);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: .8rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: .7rem; color: var(--text-light); text-transform: capitalize; }
.logout-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.4);
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}
.logout-btn:hover { color: var(--red); }

/* ── Main Content ────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Header ──────────────────────────────────────────────── */
.top-header {
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title h1 { font-size: 1.05rem; font-weight: 700; color: var(--text-main); }
.page-title p  { font-size: .78rem; color: var(--text-muted); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.notif-btn {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  color: var(--text-muted);
  transition: background var(--transition);
}
.notif-btn:hover { background: var(--border); }
.notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  border: 2px solid var(--card);
}

/* ── Page Body ───────────────────────────────────────────────── */
.page-body { padding: 24px; flex: 1; }

/* ── Stats Grid ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon.navy  { background: rgba(15,30,60,.08); color: var(--navy); }
.stat-icon.gold  { background: rgba(201,168,76,.12); color: #b8860b; }
.stat-icon.green { background: rgba(22,163,74,.1);  color: var(--green); }
.stat-icon.red   { background: rgba(220,38,38,.1);  color: var(--red); }
.stat-icon.blue  { background: rgba(37,99,235,.1);  color: var(--blue); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; color: var(--text-main); }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: .95rem; font-weight: 700; color: var(--text-main); }
.card-body { padding: 20px; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead tr { border-bottom: 2px solid var(--border); }
thead th { padding: 10px 14px; text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:hover { background: var(--surface); }
tbody td { padding: 12px 14px; color: var(--text-main); vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-draft     { background: #f1f5f9; color: #64748b; }
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-returned  { background: #fee2e2; color: #991b1b; }
.badge-approved  { background: #dcfce7; color: #166534; }
.badge-dispatched{ background: #dbeafe; color: #1e40af; }
.badge-closed    { background: #f3f4f6; color: #374151; }
.badge-urgent    { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Age indicators ──────────────────────────────────────────── */
.age-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.age-green .age-dot  { background: var(--green); }
.age-yellow .age-dot { background: var(--yellow); }
.age-red .age-dot    { background: var(--red); }
.age-green  { color: var(--green); font-weight: 600; }
.age-yellow { color: var(--yellow); font-weight: 600; }
.age-red    { color: var(--red); font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-light); }
.btn-gold      { background: var(--gold); color: var(--navy); }
.btn-gold:hover{ background: var(--gold-light); }
.btn-success   { background: var(--green); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger    { background: var(--red); color: #fff; }
.btn-danger:hover  { opacity: .9; }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text-main); }
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-main); margin-bottom: 6px; }
.form-label .required { color: var(--red); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text-main);
  background: var(--card);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(15,30,60,.08); }
.form-control.urdu  { direction: rtl; font-family: 'Noto Nastaliq Urdu', serif; font-size: 1rem; }
textarea.form-control { resize: vertical; min-height: 120px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: .75rem; color: var(--red); margin-top: 4px; }

/* ── Alert / Flash ───────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── File View / Draft Composer ──────────────────────────────── */
.draft-composer {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.draft-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.toolbar-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: .8rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.toolbar-btn:hover { border-color: var(--border); background: var(--card); color: var(--text-main); }
.toolbar-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.toolbar-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.draft-body {
  min-height: 300px;
  padding: 20px;
  outline: none;
  font-size: .9rem;
  line-height: 1.8;
}
.draft-body[dir="rtl"] { font-family: 'Noto Nastaliq Urdu', serif; font-size: 1rem; }

/* ── Letter Preview (official format) ───────────────────────── */
.letter-preview {
  background: #fff;
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 48px;
  font-size: .9rem;
  line-height: 1.8;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.letter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 12px;
  border-bottom: 3px double var(--navy);
}
.letter-header-center { flex: 1; text-align: center; padding: 0 20px; }
.letter-header-center h1 { font-size: 1rem; font-weight: 800; text-transform: uppercase; text-decoration: underline; color: var(--navy); }
.letter-header-center .phone { font-size: .82rem; font-weight: 700; color: var(--text-main); }
.letter-header-center .email { font-size: .82rem; color: var(--blue); }
.letter-logo { height: 72px; width: auto; }
.letter-meta { display: flex; justify-content: space-between; margin: 16px 0 24px; font-size: .82rem; }
.letter-meta strong { font-weight: 700; }
.letter-subject { font-weight: 700; text-decoration: underline; margin-bottom: 16px; }
.letter-body { margin-bottom: 32px; }
.letter-signature { margin-top: 40px; }
.letter-signature .designation { font-weight: 700; color: var(--navy); }

/* ── Remarks Panel ───────────────────────────────────────────── */
.remarks-panel {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.remark-item {
  background: #fff;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}
.remark-item:last-child { margin-bottom: 0; }
.remark-meta { font-size: .75rem; color: var(--text-muted); margin-bottom: 4px; }
.remark-text { font-size: .85rem; color: var(--text-main); }

/* ── Timeline ────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 20px; }
.tl-dot {
  position: absolute;
  left: -20px;
  top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--card);
  box-shadow: 0 0 0 2px var(--border);
}
.tl-dot.created   { background: var(--blue); box-shadow: 0 0 0 2px #bfdbfe; }
.tl-dot.submitted { background: var(--gold); box-shadow: 0 0 0 2px #fde68a; }
.tl-dot.returned  { background: var(--red); box-shadow: 0 0 0 2px #fca5a5; }
.tl-dot.approved  { background: var(--green); box-shadow: 0 0 0 2px #bbf7d0; }
.tl-dot.dispatched{ background: var(--navy); box-shadow: 0 0 0 2px #bfdbfe; }
.tl-time { font-size: .72rem; color: var(--text-light); margin-bottom: 2px; }
.tl-action { font-size: .85rem; font-weight: 600; color: var(--text-main); }
.tl-remarks { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; padding: 4px; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Checklist ───────────────────────────────────────────────── */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--navy); flex-shrink: 0; }
.checklist-name { flex: 1; font-size: .85rem; }
.checklist-required { font-size: .72rem; color: var(--red); }

/* ── Notification Dropdown ───────────────────────────────────── */
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  display: none;
}
.notif-dropdown.open { display: block; }
.notif-dd-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: .85rem; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.notif-item:hover { background: var(--surface); }
.notif-item.unread { background: #f0f7ff; }
.notif-item-title { font-size: .82rem; font-weight: 600; margin-bottom: 2px; }
.notif-item-msg { font-size: .78rem; color: var(--text-muted); }
.notif-item-time { font-size: .7rem; color: var(--text-light); margin-top: 4px; }
.notif-dd-footer { padding: 10px 16px; text-align: center; }
.notif-dd-footer a { font-size: .8rem; color: var(--blue); font-weight: 600; }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { opacity: .3; margin: 0 auto 16px; }
.empty-state h3 { font-size: .95rem; font-weight: 700; color: var(--text-main); margin-bottom: 6px; }
.empty-state p  { font-size: .82rem; }

/* ── Flag banner ─────────────────────────────────────────────── */
.flag-banner {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: .85rem;
  color: #991b1b;
  font-weight: 500;
}

/* ── Print styles ────────────────────────────────────────────── */
@media print {
  .sidebar, .top-header, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .letter-preview { border: none; padding: 0; max-width: 100%; }
  body { background: #fff; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Utility ─────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); font-size: .82rem; }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.fw-bold { font-weight: 700; }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-gold { color: var(--gold); }
.w-full { width: 100%; }
