/* ============================================================
   Rent Manager - Main Stylesheet
   ============================================================ */

:root {
  --primary: #1a56db;
  --primary-dark: #1341b0;
  --primary-light: #e8f0fe;
  --secondary: #374151;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --sidebar-w: 250px;
  --header-h: 60px;
  --radius: 10px;
  --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);
}

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

html { font-size: 15px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* ---- Layout ---- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-brand {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #1f2937;
}

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

.sidebar-brand .brand-name {
  font-size: 1rem; font-weight: 700; color: #fff;
  line-height: 1.2;
}
.sidebar-brand .brand-sub {
  font-size: 0.7rem; color: #6b7280;
}

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

.nav-section {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: #4b5563;
  padding: 14px 20px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: #9ca3af;
  font-size: 0.875rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.nav-item:hover { background: #1f2937; color: #fff; text-decoration: none; }
.nav-item.active { background: #1e3a5f; color: #fff; border-left-color: var(--primary); }
.nav-item .nav-icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid #1f2937;
  font-size: 0.8rem; color: #4b5563;
}
.sidebar-footer .user-name { color: #d1d5db; font-weight: 600; }
.sidebar-footer .user-role { font-size: 0.72rem; }
.sidebar-footer .logout-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; color: #ef4444; font-size: 0.8rem;
}
.sidebar-footer .logout-btn:hover { text-decoration: underline; }

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

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

.menu-toggle {
  display: none;
  background: none; border: none;
  font-size: 1.3rem; cursor: pointer; color: var(--secondary);
  padding: 4px 8px;
}

.topbar-title { font-size: 1.05rem; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

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

/* ---- Cards ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }

/* ---- Stat Cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 18px 20px;
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger);  }
.stat-icon.cyan   { background: var(--info-light);    color: var(--info);    }
.stat-info .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-info .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  background: #f9fafb; padding: 10px 14px;
  text-align: left; font-weight: 600; font-size: 0.8rem;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 7px;
  font-size: 0.875rem; font-weight: 500;
  border: none; cursor: pointer;
  transition: all 0.15s; text-decoration: none !important;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover   { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover   { background: #047857; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover   { background: #b45309; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover    { background: #b91c1c; }
.btn-secondary { background: #e5e7eb; color: var(--secondary); }
.btn-secondary:hover { background: #d1d5db; }
.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--secondary); }
.btn-outline:hover   { background: #f3f4f6; }
.btn-info      { background: var(--info); color: #fff; }
.btn-info:hover      { background: #0e7490; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; color: var(--secondary); }
.form-label .req { color: var(--danger); }
.form-control, .form-select {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 0.875rem; color: var(--text);
  background: #fff; transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.form-control:focus, .form-select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-text { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

/* ---- Alerts / Flash ---- */
.alert {
  padding: 12px 16px; border-radius: 8px;
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px; font-size: 0.875rem;
}
.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: var(--danger-light);  color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }
.alert-info    { background: var(--info-light);    color: #164e63; border: 1px solid #67e8f9; }

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 2px 9px;
  border-radius: 999px; font-size: 0.72rem; font-weight: 600;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info    { background: var(--info-light);    color: #164e63; }
.badge-secondary { background: #e5e7eb; color: #374151; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }

/* ---- Modal ---- */
.modal-overlay {
  display: none; position: fixed;
  inset: 0; z-index: 200;
  background: rgba(0,0,0,0.45);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius);
  width: 100%; max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-height: 90vh; overflow-y: auto;
}
.modal-lg { max-width: 780px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Items table in challan/bill ---- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { background: #f3f4f6; padding: 8px 10px; font-size: 0.8rem; font-weight: 600; text-align: left; border: 1px solid var(--border); }
.items-table td { padding: 7px 10px; border: 1px solid var(--border); font-size: 0.85rem; }
.items-table td input, .items-table td select {
  width: 100%; border: 1px solid #ddd; border-radius: 5px;
  padding: 5px 7px; font-size: 0.85rem; font-family: inherit;
}
.items-table td input:focus, .items-table td select:focus {
  outline: none; border-color: var(--primary);
}
.remove-row { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: 2px 6px; }
.remove-row:hover { color: #7f1d1d; }

/* ---- Print Area ---- */
.print-document { display: none; }
@media print {
  .sidebar, .topbar, .page-body > .card:not(.print-document),
  .no-print, .btn, .menu-toggle { display: none !important; }
  .print-document { display: block !important; }
  body { background: white; }
  .main-content { margin-left: 0; }
  .page-body { padding: 0; }
}
.print-doc-inner {
  padding: 30px; max-width: 800px; margin: 0 auto;
  font-family: 'Segoe UI', sans-serif;
}
.print-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.print-company h1 { font-size: 1.4rem; font-weight: 700; }
.print-company p { font-size: 0.85rem; color: #555; }
.print-doc-title { text-align: right; }
.print-doc-title h2 { font-size: 1.6rem; font-weight: 700; color: var(--primary); text-transform: uppercase; }
.print-doc-title p { font-size: 0.85rem; color: #555; }
.print-divider { border: none; border-top: 2px solid #ddd; margin: 16px 0; }
.print-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.print-meta h4 { font-size: 0.78rem; text-transform: uppercase; color: #888; margin-bottom: 4px; }
.print-meta p { font-size: 0.9rem; }
.print-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.print-table th { background: #f3f4f6; padding: 8px 10px; font-size: 0.8rem; text-align: left; border: 1px solid #ddd; }
.print-table td { padding: 8px 10px; border: 1px solid #ddd; font-size: 0.85rem; }
.print-total { text-align: right; margin-bottom: 20px; }
.print-total table { margin-left: auto; }
.print-total td { padding: 4px 10px; font-size: 0.9rem; }
.print-total .grand-total td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid #333; }
.print-terms { border: 1px solid #e5e7eb; border-radius: 6px; padding: 14px; margin-bottom: 20px; }
.print-terms h4 { font-size: 0.8rem; font-weight: 700; margin-bottom: 6px; }
.print-terms p { font-size: 0.78rem; color: #555; white-space: pre-line; }
.print-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; text-align: center; }
.print-sign .sign-line { border-top: 1px solid #555; padding-top: 6px; font-size: 0.8rem; color: #555; }

/* ---- Login page ---- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a5f 0%, #111827 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; width: 100%; max-width: 400px; box-shadow: 0 25px 60px rgba(0,0,0,0.3); overflow: hidden; }
.login-header { background: var(--primary); padding: 28px 30px; text-align: center; color: white; }
.login-header h1 { font-size: 1.4rem; font-weight: 700; }
.login-header p  { font-size: 0.85rem; opacity: 0.85; margin-top: 4px; }
.login-body { padding: 28px 30px; }
.login-body .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 0.95rem; }

/* ---- Breadcrumb ---- */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--text); font-weight: 500; }

/* ---- Search box ---- */
.search-box { position: relative; }
.search-box input { padding-left: 34px; }
.search-box .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.9rem; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }

  .page-body { padding: 14px; }

  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3 { grid-column: span 1; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .print-meta { grid-template-columns: 1fr; }
  .print-header { flex-direction: column; gap: 12px; }

  .topbar { padding: 0 14px; }

  .btn-sm { padding: 5px 8px; }
  .card-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; border-radius: 10px; }
  table { font-size: 0.8rem; }
  thead th, tbody td { padding: 8px 10px; }
}
