*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ─── LOGIN ───────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-card {
  background: var(--card-bg);
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.login-card .subtitle {
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

/* ─── FORMS ───────────────────────────── */
input, select, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input[type="file"] {
  padding: 0.5rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
}

small {
  display: block;
  color: var(--text-light);
  margin-top: 0.25rem;
  font-size: 0.8rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row > * { flex: 1; }

.form-group { margin-bottom: 0; }

button[type="submit"], .btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

button[type="submit"]:hover, .btn-primary:hover {
  background: var(--primary-hover);
}

button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.btn-pay {
  background: var(--success);
  color: #fff;
}
.btn-pay:hover { background: #15803d; }

.btn-unpay {
  background: var(--warning);
  color: #fff;
}
.btn-unpay:hover { background: #d97706; }

.btn-download {
  background: var(--primary);
  color: #fff;
}
.btn-download:hover { background: var(--primary-hover); }

.btn-edit {
  background: #6366f1;
  color: #fff;
}
.btn-edit:hover { background: #4f46e5; }

.btn-delete {
  background: var(--danger);
  color: #fff;
}
.btn-delete:hover { background: var(--danger-hover); }

.btn-delete-user {
  background: var(--danger);
  color: #fff;
}
.btn-delete-user:hover { background: var(--danger-hover); }

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.message {
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.message.success { color: var(--success); }
.message.error { color: var(--danger); }

/* ─── HEADER ──────────────────────────── */
header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left { display: flex; align-items: center; gap: 1rem; }
.header-left h1 { font-size: 1.25rem; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#user-display-name {
  color: var(--text-light);
  font-size: 0.9rem;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-contractor { background: #dbeafe; color: #1d4ed8; }
.badge-accountant { background: #dcfce7; color: #15803d; }
.badge-admin { background: #fef3c7; color: #92400e; }

/* ─── MAIN ────────────────────────────── */
main {
  max-width: 100%;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

section {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-header h2 { font-size: 1.15rem; }

.filters {
  display: flex;
  gap: 0.5rem;
}

.filters select, .filters input {
  width: auto;
  min-width: 120px;
}

/* ─── YEAR TABS ──────────────────────── */
.year-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.year-tab {
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text-light);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s;
}

.year-tab:hover {
  background: var(--bg);
}

.year-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ─── TABLE ───────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  font-weight: 600;
  color: var(--text-light);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

tbody tr:hover { background: #f8fafc; }

tfoot td {
  border-top: 2px solid var(--text);
  border-bottom: none;
  background: #f8fafc;
}

.status-paid {
  color: var(--success);
  font-weight: 600;
}

.status-unpaid {
  color: var(--danger);
  font-weight: 600;
}

.paid-info {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 400;
}

.due-info {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
}

.due-normal {
  color: var(--text);
  font-weight: 500;
}
.due-normal .due-info { color: var(--text-light); }

.due-urgent {
  color: var(--warning);
  font-weight: 600;
}
.due-urgent .due-info { color: var(--warning); }

.due-overdue {
  color: var(--danger);
  font-weight: 600;
}
.due-overdue .due-info { color: var(--danger); }

.due-paid {
  color: var(--text-light);
  font-weight: 400;
}

.actions-cell {
  display: flex;
  gap: 0.4rem;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
}

/* ─── MODAL ───────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  max-width: 650px;
  width: 95%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.15rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}

.modal-body {
  padding: 1.5rem;
}

.modal-body h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.modal-body h3:not(:first-child) {
  margin-top: 1.5rem;
}

.modal-body table { margin-bottom: 0; }

/* ─── RESPONSIVE ──────────────────────── */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
  }

  .form-row { flex-direction: column; }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  th, td { padding: 0.5rem; font-size: 0.8rem; }
}
