/* ═══════════════════════════════════════════════════════════
   ContractorWorks — Modern Drywall Management Platform
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS Variables / Theme ──────────────────────────────── */
:root {
  --bg: #f5f6fa;
  --bg-card: #fff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-topbar: #fff;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #fff;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --sidebar-width: 250px;
  --topbar-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-topbar: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-sidebar: #94a3b8;
  --border: #334155;
  --primary-light: #1e3a5f;
  --success-light: #14532d;
  --danger-light: #450a0a;
  --warning-light: #451a03;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.3);
}
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
input, select, textarea, button { font: inherit; }

/* ─── App Shell ──────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }
.main-content { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }
.page-content { padding: 24px; flex: 1; max-width: 1400px; width: 100%; }

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width); background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  z-index: 100; overflow-y: auto;
  transition: transform .2s;
}
.sidebar-brand {
  padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-icon, .brand-icon-lg {
  background: var(--primary); color: #fff; font-weight: 700;
  border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
}
.brand-icon { width: 36px; height: 36px; font-size: 14px; }
.brand-icon-lg { width: 64px; height: 64px; font-size: 24px; margin: 0 auto 12px; }
.brand-text { color: #fff; font-weight: 600; font-size: 16px; }
.sidebar-close { display: none; background: none; border: none; color: var(--text-sidebar); font-size: 24px; cursor: pointer; margin-left: auto; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-group-label { color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 16px 20px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; color: var(--text-sidebar);
  text-decoration: none; border-radius: 0; transition: background .15s;
}
.nav-item:hover { background: var(--bg-sidebar-hover); text-decoration: none; color: var(--text-sidebar-active); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.1); padding: 8px 0; }
.user-info { display: flex; align-items: center; gap: 10px; padding: 8px 20px; color: var(--text-sidebar); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
}
.user-name { font-size: 13px; }
.nav-logout { color: var(--text-muted) !important; }

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height); background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.hamburger { display: none; background: none; border: none; cursor: pointer; color: var(--text); }
.hamburger svg { width: 24px; height: 24px; }
.page-title { font-size: 18px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.btn-icon {
  width: 36px; height: 36px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon svg { width: 18px; height: 18px; }

/* ─── Cards ──────────────────────────────────────────────── */
.content-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.content-card h2, .content-card h3 { margin-bottom: 12px; font-size: 16px; }

/* ─── Stats Grid ─────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  text-align: center;
}
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-link { font-size: 12px; margin-top: 8px; display: inline-block; }

/* ─── Content Grid ───────────────────────────────────────── */
.content-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }

/* ─── Tables ─────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--text-muted); background: var(--bg); position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--primary-light); }
.data-table-sm th, .data-table-sm td { padding: 6px 10px; font-size: 13px; }
.clickable-row { cursor: pointer; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* ─── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 4px; font-size: 13px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-card); color: var(--text);
  transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.form-full { grid-column: 1 / -1; }
.form-narrow { max-width: 480px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.checkbox-label input[type="checkbox"] { width: auto; }
.inline-select { padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); font-size: 13px; }

/* ─── Search Bar ─────────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-bar input, .search-bar select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); }
.search-bar input[type="text"] { min-width: 200px; }

/* ─── Page Header ────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.detail-actions { display: flex; gap: 8px; }

/* ─── Detail List (dl) ───────────────────────────────────── */
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.detail-list dt { font-weight: 500; color: var(--text-muted); font-size: 13px; }
.detail-list dd { margin: 0; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid transparent;
  border-radius: var(--radius); font-weight: 500; cursor: pointer;
  text-decoration: none; transition: all .15s; font-size: 14px;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--bg-card); color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.mt-2 { margin-top: 8px; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
}
.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-muted { background: var(--bg); color: var(--text-muted); }
.badge-phase { background: var(--primary-light); color: var(--primary); }

/* ─── Alerts ─────────────────────────────────────────────── */
.alert { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger); }

/* ─── Quick Actions ──────────────────────────────────────── */
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: center; }
.pagination-info { font-size: 13px; color: var(--text-muted); }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 201; width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; padding: 24px; }
.hidden { display: none !important; }

/* ─── Login ──────────────────────────────────────────────── */
body.bare { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-sidebar); }
.login-page { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--bg-card); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow-lg); }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 22px; color: var(--text); }
.login-subtitle { color: var(--text-muted); font-size: 14px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { margin-top: 8px; }

/* ─── Error Pages ────────────────────────────────────────── */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h1 { font-size: 72px; color: var(--text-muted); }
.error-page p { color: var(--text-muted); margin: 12px 0 24px; }

/* ─── Reports Hub ────────────────────────────────────────── */
.reports-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.report-card { display: block; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); transition: all .15s; text-decoration: none; color: var(--text); }
.report-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); text-decoration: none; }
.report-card h3 { font-size: 16px; margin-bottom: 4px; }
.report-card p { font-size: 13px; color: var(--text-muted); }

/* ─── Line Items (dynamic rows) ──────────────────────────── */
.line-items-table { margin-top: 12px; }
.line-items-table .row-actions { width: 40px; text-align: center; }
.btn-remove-row { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .page-content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .content-grid, .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .search-bar { flex-direction: column; }
  .search-bar input[type="text"] { min-width: unset; width: 100%; }
  .page-header { flex-direction: column; align-items: stretch; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list dt { margin-top: 8px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* iPad landscape */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { --sidebar-width: 220px; width: var(--sidebar-width); }
  .main-content { margin-left: 220px; }
}
