/* ================================================
   Invoice Portal — Main Stylesheet
   Clean, professional, simple design
   ================================================ */

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

/* ---- CSS Variables ---- */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ---- Topbar / Header ---- */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--gray-900);
}

.topbar-brand .logo-icon {
  width: 34px;
  height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
}

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

/* ---- Layout ---- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.container-sm {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px;
}

/* ---- Cards ---- */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-800);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  transform: translateY(-1px);
  color: white;
  text-decoration: none;
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover:not(:disabled) {
  background: #15803d;
  transform: translateY(-1px);
  color: white;
  text-decoration: none;
}

.btn-outline {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover:not(:disabled) {
  background: var(--gray-100);
  transform: translateY(-1px);
  text-decoration: none;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius);
}

/* ---- Forms ---- */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
  transition: var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-control::placeholder { color: var(--gray-400); }

select.form-control { cursor: pointer; }

/* ---- Tables ---- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--gray-50);
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--gray-200);
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--gray-50); }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ---- Alerts ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fde68a; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #bfdbfe; }

/* ---- Login Page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-50);
  padding: 24px;
}

.login-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .icon {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 12px;
  color: white;
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gray-900);
}

.login-logo p {
  color: var(--gray-500);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ---- Stats Grid ---- */
.stats-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(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

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

.stat-icon.blue { background: var(--primary-light); }
.stat-icon.green { background: var(--success-light); }
.stat-icon.yellow { background: var(--warning-light); }

.stat-info .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1;
}

.stat-info .label {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ---- Partner Grid ---- */
.partner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.partner-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  position: relative;
}

.partner-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.partner-card .partner-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.partner-card .partner-center {
  font-size: 0.82rem;
  color: var(--gray-500);
  margin-bottom: 12px;
}

.partner-card .partner-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.partner-card-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}

.partner-card:hover .partner-card-actions { opacity: 1; }

/* ---- Month Accordion ---- */
.accordion-group {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  background: white;
}

/* For nested accordions, remove border and margin, and add left indent */
.accordion-body .accordion-group {
  border: none;
  border-top: 1px solid var(--gray-200);
  border-radius: 0;
  margin-bottom: 0;
}

.accordion-header {
  padding: 16px;
  background: var(--gray-50);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--gray-800);
  transition: background 0.2s;
}
.accordion-header:hover { background: var(--gray-100); }

/* Lighter background for nested headers */
.accordion-body .accordion-header {
  background: white;
  padding-left: 32px;
}
.accordion-body .accordion-header:hover { background: var(--gray-50); }

/* Even lighter and more indent for 3rd level */
.accordion-body .accordion-body .accordion-header {
  padding-left: 48px;
  font-weight: 500;
}

.accordion-header .chevron {
  transition: transform 0.3s;
  display: inline-block;
  margin-left: 8px;
}
.accordion-group.open > .accordion-header .chevron { transform: rotate(180deg); }

.accordion-body {
  display: none;
  border-top: 1px solid var(--gray-200);
  background: white;
}

.accordion-body .accordion-body {
  border-top: none;
}

.accordion-group.open > .accordion-body { display: block; }

/* ---- Invoice Item ---- */
.invoice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius);
  transition: var(--transition);
  gap: 12px;
}

.invoice-item:hover { background: var(--gray-50); }

.invoice-item .file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.invoice-item .file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.invoice-item .file-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.invoice-item .file-meta {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.invoice-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---- File Upload Zone ---- */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone .upload-icon {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}

.upload-zone h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.upload-zone p {
  font-size: 0.8rem;
  color: var(--gray-400);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ---- Progress Bar ---- */
.progress-bar-wrapper {
  height: 6px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.active .modal { transform: scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-900);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 1.2rem;
  padding: 4px;
  border-radius: var(--radius);
  transition: var(--transition);
}

.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}

/* ---- Link Box ---- */
.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

.link-box .link-text {
  flex: 1;
  font-size: 0.82rem;
  color: var(--gray-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: monospace;
}

/* ---- Sidebar + Main Layout ---- */
.app-layout {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 240px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 16px 0;
  flex-shrink: 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 4px;
}

.sidebar-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-400);
  padding: 10px 12px 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray-600);
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
  text-decoration: none;
}

.sidebar-item:hover,
.sidebar-item.active {
  background: var(--primary-light);
  color: var(--primary);
  text-decoration: none;
}

.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ---- Toast Notification ---- */
#toast-container {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 380px;
  animation: slideIn 0.2s ease;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.toast.hiding { animation: slideOut 0.2s ease forwards; }

/* ---- Section Heading ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gray-900);
}

.section-subtitle {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

.empty-state p {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--gray-500);
}

.empty-state small {
  font-size: 0.82rem;
  color: var(--gray-400);
}

/* ---- Partner Portal Page ---- */
.partner-page {
  min-height: 100vh;
  background: var(--gray-50);
}

.partner-header {
  background: linear-gradient(135deg, var(--primary) 0%, #4338ca 100%);
  color: white;
  padding: 32px 24px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.1);
}

.partner-welcome {
  font-size: 1.75rem;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.partner-center-name {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.8);
  font-weight: 500;
}


/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Spinner ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .partner-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .container { padding: 16px; }
  .modal { padding: 20px; }
}

/* ---- Utility ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--gray-500); }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }
.hidden { display: none !important; }
