:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #e0e2e7;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-contrast: #ffffff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.08);
  --nav-bg: #161a23;
  --nav-text: #e7e9ee;
}

:root[data-theme="dark"] {
  --bg: #11131a;
  --bg-elevated: #1a1d27;
  --text: #e7e9ee;
  --text-muted: #9aa1b1;
  --border: #2a2e3a;
  --primary: #4d8bff;
  --primary-hover: #76a6ff;
  --primary-contrast: #0b0e14;
  --success: #3ecf7e;
  --warning: #f0a93c;
  --danger: #f36a6a;
  --info: #3fc4df;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px rgba(0,0,0,0.35);
  --nav-bg: #0c0e13;
  --nav-text: #e7e9ee;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Layout */
.container { max-width: 1080px; margin: 0 auto; padding: 0 1rem; }
.container-narrow { max-width: 640px; margin: 0 auto; padding: 0 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.col { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.cluster { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
/* Subtask row: checkbox + title + delete. align-items:flex-start (not .cluster's
   center) so the delete button stays pinned to the top when the title wraps to
   two lines, instead of drifting to vertical-center of the wrapped text. */
.subtask-row { display: flex; align-items: flex-start; gap: .5rem; }
.subtask-toggle { display: flex; align-items: flex-start; gap: .5rem; flex: 1; min-width: 0; background: none; border: none; padding: 0; margin: 0; text-align: left; }
.subtask-toggle .subtask-check { flex-shrink: 0; }
.subtask-toggle .subtask-title { flex: 1; min-width: 0; overflow-wrap: break-word; padding-top: .3rem; }
/* Card galleries: CSS grid instead of flex-wrap so a half-empty last row
   doesn't stretch its leftover cards wider than the rows above it. */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--grid-min, 220px), 1fr)); gap: 1rem; }
.main { padding: 1.5rem 0 4rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* Navbar */
.navbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  padding: 0 1rem;
}
.navbar .container { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.navbar-brand { color: var(--nav-text); font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.navbar-nav { display: flex; align-items: center; gap: 1.1rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.navbar-nav a { color: var(--nav-text); opacity: .85; font-size: .92rem; }
.navbar-nav a:hover { opacity: 1; text-decoration: none; }
.navbar-nav a.active { opacity: 1; font-weight: 600; }
.navbar-toggle-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.25); color: var(--nav-text);
  border-radius: 999px; padding: .35rem .7rem; cursor: pointer; font-size: .85rem;
}
.navbar-mobile-toggle { display: none; background: none; border: none; color: var(--nav-text); font-size: 1.4rem; cursor: pointer; }

/* Cards */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.2rem;
}
.card-title { font-weight: 600; margin-bottom: .25rem; }
.card-link { display: block; }
.card-link:hover { border-color: var(--primary); text-decoration: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  border-radius: 8px; padding: .5rem .9rem; font-size: .9rem; cursor: pointer;
  font-family: inherit;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--text-muted); }
.form-group { margin-bottom: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], textarea, select {
  width: 100%; background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
  font-size: .92rem; font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; }
.checkbox-row input { width: auto; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .4rem; }

/* Badges */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.badge-low { background: rgba(22,163,74,.15); color: var(--success); }
.badge-medium { background: rgba(217,119,6,.15); color: var(--warning); }
.badge-high { background: rgba(220,38,38,.15); color: var(--danger); }
.badge-urgent { background: var(--danger); color: #fff; }
.badge-open { background: rgba(8,145,178,.15); color: var(--info); }
.badge-in_progress { background: rgba(217,119,6,.15); color: var(--warning); }
.badge-blocked { background: rgba(220,38,38,.15); color: var(--danger); }
.badge-done { background: rgba(22,163,74,.15); color: var(--success); }
.badge-muted { background: var(--border); color: var(--text-muted); }

/* Alerts */
.alert { border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; }
.alert-danger { background: rgba(220,38,38,.1); color: var(--danger); border-color: rgba(220,38,38,.25); }
.alert-success { background: rgba(22,163,74,.1); color: var(--success); border-color: rgba(22,163,74,.25); }

/* Progress bar */
.progress { background: var(--border); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar { background: var(--success); height: 100%; transition: width .2s; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); font-size: .88rem; }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }

/* Misc */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .82rem; }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; }
.image-grid .thumb { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 1; }
.image-grid .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-grid .thumb form { position: absolute; top: 4px; right: 4px; }
.image-grid .thumb button { background: rgba(0,0,0,.55); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; line-height: 1; }
.jobsite-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .6rem; background: var(--border); border-radius: 999px; font-size: .8rem; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.contact-icon-link { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); }

@media (max-width: 720px) {
  .navbar-nav { display: none; }
  .navbar-nav.open { display: flex; flex-direction: column; position: absolute; top: 56px; left: 0; right: 0; background: var(--nav-bg); padding: 1rem; z-index: 20; }
  .navbar-mobile-toggle { display: inline-block; }
  .row { flex-direction: column; }
}
