/* ─────────────────────────────────────────────────────────────────────────────
   RoofOps — Design System
   Palette: warm earthy neutrals · terracotta accent · sage secondary
   Typography: Cormorant Garamond (headings) · DM Sans (UI/body)
───────────────────────────────────────────────────────────────────────────── */

:root {
  /* Core palette */
  --bg:           #F5F0EB;
  --surface:      #EAE4DC;
  --surface2:     #DDD6CC;
  --surface3:     #D0C9BF;
  --border:       #C8C0B6;
  --border-light: #DDD6CC;

  /* Accent */
  --accent:       #C4622D;
  --accent-hover: #A8501F;
  --accent-dim:   #F5E9E1;
  --accent-text:  #7A3318;

  /* Text */
  --text:         #2C2C2C;
  --text-muted:   #8A7F76;
  --text-light:   #ADA49A;

  /* Semantic */
  --success:      #5C7A52;
  --success-bg:   #EBF2E8;
  --success-text: #3A5230;
  --warning:      #B8722A;
  --warning-bg:   #FDF3E7;
  --warning-text: #7A4A10;
  --danger:       #963030;
  --danger-hover: #7A2020;
  --danger-bg:    #FAEAEA;
  --danger-text:  #6B1A1A;
  --info-bg:      #EBF0F7;
  --info-text:    #2D4A7A;
  --sage:         #7C8C6E;
  --sage-bg:      #EFF2EB;

  /* Sidebar — dark charcoal */
  --sidebar-bg:     #242220;
  --sidebar-border: #333028;
  --sidebar-text:   #D8D2C8;
  --sidebar-muted:  #7A736A;
  --sidebar-hover:  #302E2C;
  --sidebar-active: rgba(196,98,45,0.18);
  --sidebar-accent: #C4622D;
  --sidebar-w:      228px;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(44,35,28,0.06);
  --shadow-sm: 0 2px 8px rgba(44,35,28,0.08), 0 0 0 1px rgba(44,35,28,0.04);
  --shadow-md: 0 4px 16px rgba(44,35,28,0.10), 0 0 0 1px rgba(44,35,28,0.04);
  --shadow-lg: 0 12px 40px rgba(44,35,28,0.14);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Cormorant Garamond', 'Playfair Display', Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.25;
}

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

/* ─────────────────────────────────────────────────────────────────────────────
   Layout
───────────────────────────────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

/* ─────────────────────────────────────────────────────────────────────────────
   Sidebar
───────────────────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s;
  overflow: hidden;
}

.sidebar-logo {
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo .logo-mark {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  color: #E8E0D5;
  letter-spacing: 0.02em;
}
.sidebar-logo .logo-sub {
  font-size: 10px;
  color: var(--sidebar-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section-label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  padding: 10px 8px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 400;
  transition: background 0.14s, color 0.14s;
  margin-bottom: 1px;
  opacity: 0.85;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #E8E0D5;
  opacity: 1;
}
.nav-item.active {
  background: var(--sidebar-active);
  color: #E8916A;
  opacity: 1;
  font-weight: 500;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

/* Nav submenu */
.nav-group { margin-bottom: 1px; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
  user-select: none;
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
  text-align: left;
  opacity: 0.85;
}
.nav-group-toggle:hover { background: var(--sidebar-hover); color: #E8E0D5; opacity: 1; }
.nav-group-toggle.active { color: #E8916A; opacity: 1; }
.nav-group-toggle svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }
.nav-group-arrow { margin-left: auto; width: 11px !important; height: 11px !important; transition: transform 0.2s; }
.nav-group.open .nav-group-arrow { transform: rotate(90deg); }
.nav-submenu { display: none; padding-left: 18px; margin-top: 1px; }
.nav-group.open .nav-submenu { display: block; }
.nav-submenu .nav-item { font-size: 12.5px; padding: 6px 10px; }

/* Sidebar footer */
.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--sidebar-border);
}
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--sidebar-active);
  color: #E8916A;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
  border: 1px solid rgba(196,98,45,0.25);
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 12.5px; color: var(--sidebar-text); }
.user-role { font-size: 10.5px; color: var(--sidebar-muted); text-transform: capitalize; }
.logout-btn { font-size: 16px; color: var(--sidebar-muted); padding: 4px 6px; border-radius: 4px; }
.logout-btn:hover { color: #E8916A; background: var(--sidebar-hover); }

/* ─────────────────────────────────────────────────────────────────────────────
   Main content area
───────────────────────────────────────────────────────────────────────────── */

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 0 28px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 90;
  box-shadow: var(--shadow-xs);
}
.topbar-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

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

.content { padding: 28px 32px; flex: 1; max-width: 1400px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Cards
───────────────────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-xs);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Buttons
───────────────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  box-shadow: 0 2px 8px rgba(196,98,45,0.25);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface2);
  border-color: var(--surface3);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }

.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Badges
───────────────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* Job statuses */
.badge-lead       { background: var(--surface2);  color: var(--text-muted); border: 1px solid var(--border); }
.badge-quote      { background: #EBF0F7;           color: #2D4A7A; border: 1px solid #C5D5E8; }
.badge-approved   { background: var(--success-bg); color: var(--success-text); border: 1px solid #C8DBC2; }
.badge-inprogress { background: #F0EAF6;           color: #5A3A7A; border: 1px solid #D5C5E8; }
.badge-onhold     { background: var(--warning-bg); color: var(--warning-text); border: 1px solid #EDD5B0; }
.badge-complete   { background: var(--success-bg); color: var(--success-text); border: 1px solid #C8DBC2; }
.badge-invoiced   { background: var(--accent-dim); color: var(--accent-text); border: 1px solid #E8C9B5; }
.badge-closed     { background: var(--surface2);   color: var(--text-light); border: 1px solid var(--border); }
.badge-danger     { background: var(--danger-bg);  color: var(--danger-text); border: 1px solid #E8C0C0; }
.badge-warning    { background: var(--warning-bg); color: var(--warning-text); border: 1px solid #EDD5B0; }

/* ─────────────────────────────────────────────────────────────────────────────
   Tables
───────────────────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table, .data-table { width: 100%; border-collapse: collapse; }

.data-table th, th {
  text-align: left;
  padding: 10px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  background: var(--surface);
}

.data-table td, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.td-mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Forms
───────────────────────────────────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

.form-label, label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.form-control,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="file"],
input[type="tel"],
input[type="url"],
select,
textarea {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13.5px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
.form-control:focus,
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196,98,45,0.10);
}
textarea { resize: vertical; min-height: 80px; }
input::placeholder, textarea::placeholder { color: var(--text-light); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A7F76' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
input[type="file"] { padding: 7px 10px; cursor: pointer; }
input[type="checkbox"] { width: auto; }
input[type="radio"] { width: auto; }

.form-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 4px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  grid-column: 1 / -1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Flash messages
───────────────────────────────────────────────────────────────────────────── */

.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid;
}
.flash-success { background: var(--success-bg); border-color: var(--success); color: var(--success-text); }
.flash-error   { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger-text); }
.flash-info    { background: var(--info-bg);    border-color: #3B6CB0;         color: var(--info-text); }
.flash-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning-text); }

/* ─────────────────────────────────────────────────────────────────────────────
   Stat cards / Dashboard
───────────────────────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-xs);
}
.stat-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}
.stat-card .stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Detail view
───────────────────────────────────────────────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
}
.detail-item label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}
.detail-item .val { color: var(--text); font-size: 14px; }
.detail-item .val-mono { font-family: monospace; }

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 8px;
}
.section-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Search / filter bar
───────────────────────────────────────────────────────────────────────────── */

.search-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 18px;
}
.search-bar input { max-width: 280px; }
.search-bar select { max-width: 160px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Pagination
───────────────────────────────────────────────────────────────────────────── */

.pagination { display: flex; gap: 6px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.page-btn {
  padding: 5px 11px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px;
  cursor: pointer; text-decoration: none;
  font-family: 'DM Sans', sans-serif;
}
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:hover:not(.active) { background: var(--surface2); }
.page-info { color: var(--text-muted); font-size: 12px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Login page
───────────────────────────────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 30% 70%, rgba(196,98,45,0.06) 0%, transparent 60%),
                    radial-gradient(ellipse at 70% 20%, rgba(124,140,110,0.06) 0%, transparent 60%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo { margin-bottom: 32px; }
.login-logo h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 26px; font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 5px; }
.login-logo .logo-accent { color: var(--accent); }

/* ─────────────────────────────────────────────────────────────────────────────
   Divider
───────────────────────────────────────────────────────────────────────────── */

.divider { height: 1px; background: var(--border-light); margin: 20px 0; }

/* ─────────────────────────────────────────────────────────────────────────────
   Notification bell
───────────────────────────────────────────────────────────────────────────── */

.notif-wrap { position: relative; }
.notif-bell {
  position: relative;
  background: none; border: none; cursor: pointer;
  padding: 7px; border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: flex; align-items: center;
  transition: background 0.14s, color 0.14s;
}
.notif-bell:hover { background: var(--surface2); color: var(--text); }
.notif-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff; font-size: 9px; font-weight: 700;
  line-height: 16px; text-align: center;
  pointer-events: none;
}
.notif-panel {
  position: absolute;
  top: calc(100% + 10px); right: 0;
  width: 340px; max-height: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.notif-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 16px;
  font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  flex-shrink: 0;
  color: var(--text);
}
#notif-list { overflow-y: auto; flex: 1; }
.notif-empty {
  padding: 28px 16px; text-align: center;
  color: var(--text-muted); font-size: 13px;
}
.notif-item {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light);
  border-left: 3px solid transparent;
}
.notif-item:last-child { border-bottom: none; }
.notif-red   { border-left-color: var(--danger);  background: var(--danger-bg); }
.notif-amber { border-left-color: var(--warning); background: var(--warning-bg); }
.notif-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  text-decoration: none; display: block; line-height: 1.3;
}
.notif-title:hover { color: var(--accent); }
.notif-msg { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }

/* ─────────────────────────────────────────────────────────────────────────────
   Misc utilities
───────────────────────────────────────────────────────────────────────────── */

.text-muted    { color: var(--text-muted); }
.text-right    { text-align: right; }
.mt-16         { margin-top: 16px; }
.mb-16         { margin-bottom: 16px; }
.flex          { display: flex; }
.gap-8         { gap: 8px; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.font-mono     { font-family: monospace; }

/* ─────────────────────────────────────────────────────────────────────────────
   Overlay / mobile
───────────────────────────────────────────────────────────────────────────── */

.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(36,34,32,0.55);
  z-index: 99;
}
.overlay.open { display: block; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 16px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Dashboard-specific
───────────────────────────────────────────────────────────────────────────── */

/* Job status colour bar */
.job-status-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--border-light);
  overflow: hidden;
  margin-top: 8px;
}
.job-status-fill { height: 100%; border-radius: 2px; background: var(--accent); }

/* ─────────────────────────────────────────────────────────────────────────────
   Mia Assistant overrides (keeps earthy palette)
───────────────────────────────────────────────────────────────────────────── */

#mia-help-btn { background: #fff; color: var(--accent); border-color: var(--accent); }
#mia-chat-btn { background: var(--accent); }
#mia-chat-header { background: var(--accent); }
#mia-chat-panel { border: 1px solid var(--border); }
.mia-msg.user { background: var(--accent); }
.mia-msg.assistant { background: var(--surface2); color: var(--text); }
#mia-input { background: var(--surface); border-color: var(--border); color: var(--text); }
#mia-input:focus { border-color: var(--accent); }
#mia-send-btn { background: var(--accent); }
#mia-help-box { background: var(--surface); }
#mia-help-box h3 { color: var(--accent); }
#mia-help-box p, #mia-help-box ul { color: var(--text); }
.mia-label { color: var(--accent); }
.mia-close-btn { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
