:root {
  --navy-dark: #0a3a52;
  --navy-mid: #123a52;
  --navy-light: #1c4f6b;
  --navy-gradient-start: #0a3550;
  --navy-gradient-end: #14607e;
  --purple: #362f6e;
  --purple-sub: #6d4fa8;
  --poststatus: #1d5f74;
  --reelcount: #3f7a8c;
  --total-color: #8a5220;
  --teal: #0e5c54;
  --grey-dark: #3a3a3a;
  --grey-sub: #52606d;
  --accent-cyan: #4fc3f7;
  --blue-btn: #1e73d6;
  --bg-body: #f3f5f9;
  --card-white: #ffffff;
  --border-light: #e5e9f0;
  --text-dark: #16202b;
  --text-muted: #6b7686;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text-dark);
}

/* ============ TOP BAR ============ */
.topbar {
  background: linear-gradient(135deg, var(--navy-gradient-start) 0%, var(--navy-gradient-end) 100%);
  color: #fff;
  padding: 20px 28px 0 28px;
}

.topbar-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
}

.topbar-titles h1 {
  margin: 0 0 4px 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.topbar-titles p {
  margin: 0;
  font-size: 14px;
  color: rgba(255,255,255,0.75);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.topbar-logout {
  color: #fff;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.3);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.topbar-logout:hover { background: rgba(255,255,255,0.22); }

.tabs {
  display: flex;
  gap: 28px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 4px;
  border-bottom: 3px solid transparent;
}

.tab-active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
}

/* ============ MAIN CONTENT ============ */
.main-content {
  padding: 24px 28px 60px 28px;
  max-width: 1600px;
  margin: 0 auto;
}

/* ============ STAT CARDS ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-white);
  border-radius: 14px;
  padding: 18px 18px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
  border: 1px solid var(--border-light);
}

.stat-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-dark);
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-blue    { background: #dbeafe; color: #2563eb; }
.icon-purple  { background: #ede9fe; color: #7c3aed; }
.icon-amber   { background: #fef3c7; color: #d97706; }
.icon-green   { background: #d1fae5; color: #059669; }
.icon-cyan    { background: #cffafe; color: #0891b2; }
.icon-pink    { background: #fce7f3; color: #db2777; }

/* ============ TABLE SECTION ============ */
.table-section {
  background: var(--card-white);
  border-radius: 14px;
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 20px 16px 20px;
}

.table-toolbar h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 14px;
  width: 240px;
  outline: none;
}
.search-input:focus { border-color: var(--blue-btn); }

.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-btn);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 8px;
  white-space: nowrap;
}
.btn-add:hover { background: #185ab0; }

.table-wrap { overflow-x: auto; }

.branch-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1300px;
  font-size: 13px;
}

.branch-table th, .branch-table td {
  padding: 10px 12px;
  text-align: center;
  white-space: nowrap;
}

.branch-table thead th {
  background: var(--navy-mid);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border: 1px solid rgba(255,255,255,0.08);
}

.branch-table thead tr:first-child th { padding-top: 12px; }
.branch-table thead tr:last-child th { padding-bottom: 12px; }

.grp-purple { background: var(--purple); }
.sub-purple { background: var(--purple-sub); }
.grp-poststatus { background: var(--poststatus); }
.grp-reelcount { background: var(--reelcount); }
.grp-total { background: var(--total-color); }
.grp-teal { background: var(--teal); }
.grp-grey { background: var(--grey-dark); }
.sub-grey { background: var(--grey-sub); }
.grp-actions { background: var(--navy-mid); color: var(--accent-cyan) !important; }

.th-sub { font-size: 10px; font-weight: 500; opacity: 0.85; text-transform: none; }

.branch-table tbody td {
  border-bottom: 1px solid var(--border-light);
  color: var(--text-dark);
}

.branch-table tbody tr:hover { background: #f8fafc; }

.branch-name-cell { text-align: left; font-weight: 600; }

/* Conditional formatting - Instagram Reel counts (Excel-style color scale).
   !important guards against the base ".branch-table tbody td { color }" rule
   (and any future table-cell rule) silently overriding these. */
.cf-cell { font-weight: 700; }
.cf-none { background: #fee2e2 !important; color: #b91c1c !important; }
.cf-low  { background: #fef3c7 !important; color: #b45309 !important; }
.cf-mid  { background: #dbeafe !important; color: #1d4ed8 !important; }
.cf-high { background: #d1fae5 !important; color: #047857 !important; }

.cf-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 0 20px 14px 20px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.cf-legend-label { font-weight: 700; }
.cf-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.cf-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* Zone-wise status sort toggle */
.sort-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sort-label { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.sort-btn {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  background: #f3f5f9;
  border: 1px solid var(--border-light);
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
}
.sort-btn:hover { background: #e9edf3; }
.sort-active {
  background: var(--blue-btn);
  border-color: var(--blue-btn);
  color: #fff;
}

.zone-chip {
  display: inline-block;
  background: #eef2f9;
  color: var(--navy-mid);
  font-weight: 700;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
}

.total-cell { font-weight: 800; color: var(--total-color); }

.actions-cell { display: flex; align-items: center; justify-content: center; gap: 8px; }
.inline-form { display: inline-flex; margin: 0; }

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.action-edit { background: #e0edff; color: #1e5fbf; }
.action-edit:hover { background: #c9e0ff; }
.action-delete { background: #fde2e2; color: #c0392b; }
.action-delete:hover { background: #f9c9c9; }

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.badge-green  { background: #d1fae5; color: #047857; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-red    { background: #fde2e2; color: #b91c1c; }
.badge-neutral{ background: #eef1f5; color: #6b7686; }

/* Empty state */
.empty-row td { border-bottom: none; }
.empty-state {
  padding: 60px 20px;
  text-align: center;
}
.empty-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #eef1f5;
  color: #9aa5b1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px auto;
}
.empty-title { font-size: 17px; font-weight: 700; margin: 0 0 6px 0; }
.empty-sub { font-size: 14px; color: var(--text-muted); margin: 0; }

/* ============ FORM (Add/Edit) ============ */
.form-section { display: flex; justify-content: center; }

.form-card {
  background: var(--card-white);
  border-radius: 14px;
  border: 1px solid var(--border-light);
  padding: 28px 32px 32px 32px;
  max-width: 780px;
  width: 100%;
}

.form-card h2 { margin: 0 0 4px 0; font-size: 20px; font-weight: 800; }
.form-subtitle { margin: 0 0 22px 0; color: var(--text-muted); font-size: 14px; }

.section-heading {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  margin: 22px 0 14px 0;
  display: inline-block;
}
.section-purple { background: var(--purple); }
.section-navy   { background: var(--navy-mid); }
.section-teal   { background: var(--teal); }
.section-grey   { background: var(--grey-dark); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 4px;
}
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }
.form-group-wide { grid-column: span 1; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 700; color: var(--text-dark); }
.form-group .req { color: #dc2626; }

.form-group input, .form-group select {
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--blue-btn); }

.form-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  background: #f3f5f9;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0 0 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
  border-top: 1px solid var(--border-light);
  padding-top: 20px;
}

.btn-cancel {
  padding: 11px 22px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  color: var(--text-dark);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
}
.btn-cancel:hover { background: #f3f5f9; }

.btn-save {
  padding: 11px 26px;
  border-radius: 8px;
  border: none;
  background: var(--blue-btn);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn-save:hover { background: #185ab0; }
.btn-full { width: 100%; }

/* ============ FLASH MESSAGES ============ */
.flash-msg {
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 18px;
}
.flash-success { background: #d1fae5; color: #047857; }
.flash-error   { background: #fde2e2; color: #b91c1c; }

/* ============ LOGIN PAGE ============ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy-gradient-start) 0%, var(--navy-gradient-end) 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 34px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}

.login-header { text-align: center; margin-bottom: 22px; }
.login-header h1 { margin: 0 0 6px 0; font-size: 22px; font-weight: 800; color: var(--navy-mid); }
.login-header p { margin: 0; font-size: 13px; color: var(--text-muted); }

.login-form .form-group { margin-bottom: 16px; }

.alert-error {
  background: #fde2e2;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  font-weight: 600;
}

.login-footer { text-align: center; margin-top: 18px; }
.login-footer a { color: var(--blue-btn); font-size: 13px; text-decoration: none; font-weight: 600; }
.login-footer a:hover { text-decoration: underline; }
.login-credit { margin: 10px 0 0 0; font-size: 11.5px; color: var(--text-muted); }

/* ============ APP FOOTER ============ */
.app-footer {
  background: linear-gradient(135deg, var(--navy-gradient-start) 0%, var(--navy-gradient-end) 100%);
  color: rgba(255,255,255,0.85);
  margin-top: 32px;
}

.footer-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-left { display: flex; flex-direction: column; gap: 2px; }
.footer-left strong { font-size: 13.5px; font-weight: 700; color: #fff; }
.footer-left span { font-size: 12px; color: rgba(255,255,255,0.6); }

.footer-right { font-size: 12px; color: rgba(255,255,255,0.65); white-space: nowrap; }
.footer-right strong { color: #fff; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .topbar { padding: 16px 16px 0 16px; }
  .topbar-titles h1 { font-size: 20px; }
  .main-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .search-input { width: 100%; }
  .toolbar-actions { flex-direction: column; align-items: stretch; }
  .form-grid, .form-grid-4 { grid-template-columns: 1fr; }
  .form-card { padding: 20px; }
  .footer-inner { flex-direction: column; align-items: flex-start; padding: 16px; }
  .footer-right { white-space: normal; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 21px; }
}
