/* public/css/app.css - Invoice System Design */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --primary: #1a1f2e;
  --primary-light: #252b3d;
  --accent: #d4a853;
  --accent-light: #e8c07a;
  --accent-dark: #b8892f;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --surface-3: #f0ede6;
  --border: #e8e3d9;
  --text: #1a1f2e;
  --text-muted: #7a7568;
  --text-light: #a8a199;
  --success: #2d7a4f;
  --success-bg: #e8f5ee;
  --warning: #b8730a;
  --warning-bg: #fdf3e3;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --info: #1a6b9a;
  --info-bg: #e3f0f8;
  --sidebar-w: 260px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.sidebar-brand-logo {
  width: 40px; height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand-logo img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 10px;
}

.sidebar-brand-text {
  flex: 1;
  min-width: 0;
}

.sidebar-brand-name {
  font-family: 'Playfair Display', serif;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.5px;
}

.sidebar-nav { flex: 1; padding: 16px 12px; }

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 8px 8px 4px;
  margin-bottom: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: rgba(255,255,255,0.65);
  font-size: 13.5px;
  font-weight: 450;
  transition: all 0.2s;
  margin-bottom: 2px;
}

.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; }

.nav-link.active {
  background: var(--accent);
  color: var(--primary);
  font-weight: 600;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--primary);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.4); text-transform: capitalize; }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: rgba(255,255,255,0.45);
  font-size: 13px;
  transition: all 0.2s;
}
.sidebar-logout:hover { background: rgba(192,57,43,0.2); color: #e07b6e; }

/* ============ MAIN LAYOUT ============ */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
}

.topbar-title {
  flex: 1;
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--primary);
}

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

.page-content {
  flex: 1;
  padding: 24px;
}

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
}

.card-body { padding: 24px; }

/* ============ STAT CARDS ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}

.stat-card.green::before { background: var(--success); }
.stat-card.red::before { background: var(--danger); }
.stat-card.blue::before { background: var(--info); }

.stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-family: 'Playfair Display', serif; font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.badge-draft    { background: var(--surface-3); color: var(--text-muted); }
.badge-sent     { background: var(--info-bg); color: var(--info); }
.badge-partial  { background: var(--warning-bg); color: var(--warning); }
.badge-paid     { background: var(--success-bg); color: var(--success); }
.badge-overdue  { background: var(--danger-bg); color: var(--danger); }
.badge-cancelled{ background: var(--surface-3); color: var(--text-light); }
.badge-admin    { background: #ede9fb; color: #5b30c2; }
.badge-manager  { background: var(--info-bg); color: var(--info); }
.badge-user     { background: var(--surface-3); color: var(--text-muted); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.18s;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; }

.btn-accent { background: var(--accent); color: var(--primary); }
.btn-accent:hover { background: var(--accent-dark); color: #fff; }

.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); background: var(--surface-3); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c6c2; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-success { background: var(--success-bg); color: var(--success); border: 1px solid #a8d8be; }
.btn-success:hover { background: var(--success); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-sm svg { width: 14px; height: 14px; }

.btn-icon { padding: 7px; }

/* ============ TABLE ============ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

.table-actions { display: flex; gap: 6px; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.15);
}

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a7568' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-required { color: var(--danger); }

.form-row {
  display: grid;
  gap: 16px;
}
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ============ ALERTS / FLASH ============ */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a8d8be; }
.alert-error   { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c6c2; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #f0c57c; }
.alert-info    { background: var(--info-bg); color: var(--info); border: 1px solid #a0c8e8; }

/* ============ INVOICE ITEMS TABLE ============ */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { background: var(--surface-2); padding: 10px 12px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.items-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items-table .del-row { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: 4px; transition: color 0.2s; }
.items-table .del-row:hover { color: var(--danger); }

/* ============ SEARCH BAR ============ */
.search-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-input { position: relative; }
.search-input input { padding-left: 38px; }
.search-input svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 16px; height: 16px; }

/* ============ PAGINATION ============ */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: center; padding: 16px; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: 13px; transition: all 0.2s; }
.page-link:hover { border-color: var(--accent); color: var(--accent-dark); }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state-icon { width: 64px; height: 64px; background: var(--surface-3); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.empty-state-icon svg { width: 28px; height: 28px; color: var(--text-muted); }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.empty-state p { color: var(--text-muted); font-size: 13.5px; }

/* ============ SIDEBAR OVERLAY ============ */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .topbar-toggle { display: flex; }
  .page-content { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .topbar { padding: 0 16px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .btn span { display: none; }
  .btn-icon span { display: none; }
}

/* ============ PRINT INVOICE ============ */
@media print {
  body { background: white; font-family: 'DM Sans', sans-serif; }
  .no-print { display: none !important; }
  .print-page { width: 210mm; min-height: 297mm; padding: 16mm 18mm; background: white; }
}

/* Mono numbers */
.mono { font-family: 'DM Mono', monospace; font-size: 13px; }

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.dot-draft    { background: #aaa; }
.dot-sent     { background: var(--info); }
.dot-partial  { background: var(--warning); }
.dot-paid     { background: var(--success); }
.dot-overdue  { background: var(--danger); }
.dot-cancelled{ background: #ccc; }

/* Currency display */
.currency-display { font-family: 'DM Mono', monospace; }

/* Summary box */
.summary-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 1px dashed var(--border);
}

.summary-row:last-child { border-bottom: none; }

.summary-row.total {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  font-family: 'Playfair Display', serif;
  padding-top: 12px;
  margin-top: 4px;
}

.summary-row.dp { color: var(--warning); }
.summary-row.paid { color: var(--success); }
.summary-row.remaining { color: var(--danger); font-weight: 600; }

/* Topbar search */
.topbar-search { position: relative; display: none; }
@media (min-width: 768px) { .topbar-search { display: block; } }
.topbar-search input { padding: 7px 14px 7px 36px; border-radius: 100px; border: 1.5px solid var(--border); background: var(--surface-2); font-size: 13px; width: 220px; font-family: 'DM Sans', sans-serif; }
.topbar-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 15px; height: 15px; }

/* Invoice number */
.invoice-number-display { font-family: 'DM Mono', monospace; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; color: var(--primary); }

/* Logo preview */
.logo-preview { max-width: 140px; max-height: 70px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); }
