/* Invoice Payment Tracker — mobile-first stylesheet */

:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #e2e5ea;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-success-bg: #ecfdf5;
  --color-success-text: #047857;

  --status-pending-bg: #fef3c7;
  --status-pending-text: #92400e;
  --status-approved-bg: #dbeafe;
  --status-approved-text: #1e40af;
  --status-rejected-bg: #fee2e2;
  --status-rejected-text: #991b1b;
  --status-paid-bg: #d1fae5;
  --status-paid-text: #065f46;
  --status-partially-paid-bg: #cffafe;
  --status-partially-paid-text: #155e75;

  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);

  --bottom-nav-h: 60px;
  --topbar-h: 56px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

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

a { color: var(--color-primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; }
p { margin: 0 0 0.75em; }
.muted { color: var(--color-text-muted); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { background: #fff; color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-link { background: transparent; border-color: transparent; color: var(--color-primary); padding: 10px 8px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */

.stack-form { display: flex; flex-direction: column; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--color-text-muted); }
.form-field input,
.form-field select,
.form-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.field-hint { font-size: 12px; color: var(--color-text-muted); margin: 2px 0 0; }

#logo-preview-wrap { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.logo-preview { max-width: 200px; max-height: 80px; object-fit: contain; border: 1px solid var(--color-border); border-radius: var(--radius); padding: 8px; }
.form-error { color: var(--color-danger); font-size: 14px; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

/* ---------- Auth pages (login / change password) ---------- */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px 24px;
}
.auth-subtitle { color: var(--color-text-muted); margin-bottom: 20px; }
.auth-logo { display: block; max-width: 100%; max-height: 72px; object-fit: contain; margin-bottom: 16px; }

/* ---------- App shell ---------- */

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

.sidebar { display: none; }

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-weight: 700;
  font-size: 17px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-page-action .btn { padding: 8px 12px; font-size: 14px; }

.notif-bell-mobile {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  position: relative;
  padding: 6px;
}

.logout-btn-mobile {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
}

.page-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--bottom-nav-h) + 16px);
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 10;
}
.bottom-nav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--color-text-muted);
  border: none;
  background: none;
  cursor: pointer;
  position: relative;
}
.bottom-nav-link.active { color: var(--color-primary); }
.nav-icon { font-size: 18px; }

.notif-badge {
  background: var(--color-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}
.notif-badge-bottom { position: absolute; top: 2px; right: calc(50% - 20px); }

/* ---------- Notification panel ---------- */

.notif-panel[hidden] { display: none; }

.notif-panel {
  position: fixed;
  top: var(--topbar-h);
  right: 12px;
  left: 12px;
  max-width: 380px;
  margin-left: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  z-index: 20;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.notif-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  font-weight: 700;
}
.notif-list { overflow-y: auto; }
.notif-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  cursor: pointer;
}
.notif-item.unread { background: #eff6ff; }
.notif-item-msg { font-size: 14px; }
.notif-item-time { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 14px;
}
.tab {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Filters bar (search + date range) ---------- */

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.filters-bar input[type="search"] {
  flex: 1 1 220px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
}
.filter-date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
}
.filter-date-field input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
}
.filters-bar select {
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
}

/* ---------- Pagination ---------- */

.pagination[hidden] { display: none; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
  padding-bottom: 8px;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 20px; margin: 0; }

/* ---------- Cards & request list ---------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 16px;
}

.card-list { display: flex; flex-direction: column; gap: 10px; }

.req-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--color-text);
}
.req-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.req-card-badges { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.req-card-title { font-weight: 700; font-size: 15px; }
.req-card-sub { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }
.req-card-bottom { display: flex; justify-content: space-between; margin-top: 10px; font-size: 14px; }
.req-card-amount { font-weight: 700; }
.req-card-date { color: var(--color-text-muted); }

.req-detail-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.req-detail-amount { font-size: 22px; font-weight: 700; margin: 8px 0; }
.req-detail-desc { white-space: pre-wrap; }

.action-card h2 { font-size: 16px; }

.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 14px; margin: 14px 0; }
.meta-list dt { color: var(--color-text-muted); }
.meta-list dd { margin: 0; }

.attachment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Status badges ---------- */

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge[title] { cursor: help; }
.badge-pending { background: var(--status-pending-bg); color: var(--status-pending-text); }
.badge-approved { background: var(--status-approved-bg); color: var(--status-approved-text); }
.badge-rejected { background: var(--status-rejected-bg); color: var(--status-rejected-text); }
.badge-paid { background: var(--status-paid-bg); color: var(--status-paid-text); }
.badge-partially_paid { background: var(--status-partially-paid-bg); color: var(--status-partially-paid-text); }
.badge-first-payment { background: #ede9fe; color: #6d28d9; }

/* ---------- Banner ---------- */

.banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
.banner-success { background: var(--color-success-bg); color: var(--color-success-text); border: 1px solid #a7f3d0; }
.banner-info { background: var(--status-approved-bg); color: var(--status-approved-text); border: 1px solid #bfdbfe; }

/* ---------- Admin users table ---------- */

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--color-border); }
.data-table th { color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table-scroll { overflow-x: auto; }
.data-table tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--color-border); }
.data-table td.num, .data-table td.nowrap { white-space: nowrap; }
.data-table td.num { font-variant-numeric: tabular-nums; }
.data-table-compact { font-size: 12px; }
.data-table-compact th, .data-table-compact td { padding: 6px 8px; }
#reports-table { table-layout: fixed; }
#reports-table th { white-space: normal; }
#reports-table .badge { padding: 3px 8px; font-size: 11px; }
#reports-table td.nowrap { overflow: hidden; text-overflow: ellipsis; }

/* ---------- Dialog ---------- */

.app-dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  width: 90vw;
  max-width: 420px;
}
.app-dialog::backdrop { background: rgba(15, 23, 42, 0.5); }

/* ================= Desktop / tablet ================= */

@media (min-width: 768px) {
  .app-shell { flex-direction: row; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    height: 100vh;
    padding: 20px 14px;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
  }

  .app-main { margin-left: var(--sidebar-w); }
  .sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    font-weight: 800;
    font-size: 18px;
    margin-bottom: 24px;
    padding: 0 8px;
  }
  .sidebar-logo { max-width: 100%; max-height: 48px; object-fit: contain; }
  .sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: var(--radius);
    color: var(--color-text);
    font-weight: 600;
    font-size: 14px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    position: relative;
  }
  .sidebar-nav .nav-link:hover { background: var(--color-bg); }
  .sidebar-nav .nav-link.active { background: #eff6ff; color: var(--color-primary); }

  .sidebar-user { border-top: 1px solid var(--color-border); padding-top: 14px; margin-top: 14px; }
  .sidebar-user-name { font-weight: 700; font-size: 14px; }
  .sidebar-user-role { font-size: 12px; color: var(--color-text-muted); margin-bottom: 6px; }

  .topbar { padding: 12px 32px; }
  .topbar-title { font-size: 20px; }
  .topbar-page-action .btn { padding: 10px 16px; font-size: 15px; }
  .logout-btn-mobile { display: none; }
  .bottom-nav { display: none; }
  .page-content { padding: 32px; padding-bottom: 32px; max-width: 900px; }
  .page-content.page-wide { max-width: 1600px; }

  .notif-panel { top: 60px; left: auto; right: 24px; }
}
