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

html { overflow-x: clip; overscroll-behavior-x: none; }

:root {
  --accent: #15803d;
  --accent-dark: #14532d;
  --bg: #f6f5f0;
  --surface: #ffffff;
  --border: #e5e2d8;
  --text: #1f2420;
  --muted: #6b7066;
  --green: #15803d;
  --amber: #b45309;
  --blue: #2563eb;
  --red: #b91c1c;
  --nav-h: 84px;
}

[data-theme="dark"] {
  --bg: #1a1d19;
  --surface: #262a24;
  --border: #3b413a;
  --text: #ecefe9;
  --muted: #9ca39a;
  --green: #16a34a;
  --amber: #f59e0b;
  --blue: #60a5fa;
  --red: #f87171;
  --accent: #16a34a;
  --accent-dark: #15803d;
}

[data-theme="dark"] .table a { color: var(--accent); }
[data-theme="dark"] .table a:hover { color: #93c5fd; }
[data-theme="dark"] .message-content a { color: var(--accent); }
[data-theme="dark"] .attachment-file { color: var(--accent); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

/* Nav */
.nav {
  display: flex;
  flex-direction: column;
  background: var(--accent-dark);
  color: #fff;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1050;
  padding-top: env(safe-area-inset-top);
}
.nav-top {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 44px;
  position: relative;
}
.nav-brand {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.nav-menu-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.nav-menu-btn:hover { color: #fff; }
.nav-links {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 8px 16px 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.nav-links a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: 6px;
}
.nav-links a:hover { color: #fff; }
.nav-links a.active { color: #fff; background: rgba(255,255,255,0.18); }

/* Drawer */
.drawer {
  position: fixed;
  top: 0; left: 0;
  width: 220px;
  height: 100vh;
  background: var(--surface);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 4px 0 20px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
}
.drawer.open { transform: translateX(0); }
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 999;
  display: none;
}
.drawer-overlay.open { display: block; }
.drawer-logout {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.drawer-logout:hover { background: #fee2e2; color: var(--red); border-color: #fca5a5; }
.drawer-link { display: block; font-size: 14px; color: var(--text); text-decoration: none; padding: 7px 10px; border-radius: 6px; margin-bottom: 2px; }
.drawer-link:hover { background: var(--bg); }
.drawer-link.active { background: var(--bg); font-weight: 600; color: var(--accent); }

@media (min-width: 768px) {
  .drawer {
    transform: translateX(0);
    box-shadow: none;
    border-right: 1px solid var(--border);
    transition: none;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    height: calc(100vh - var(--nav-h) - env(safe-area-inset-top));
    padding-top: 20px;
    overflow-y: auto;
  }
  .drawer-overlay { display: none !important; }
  .nav-menu-btn { display: none; }
  body { padding-left: 220px; }
}

/* Buttons */
.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

/* Container */
.container { max-width: 900px; margin: 32px auto; padding: 0 24px; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; gap: 16px; }
.page-header h1 { font-size: 22px; font-weight: 700; }

/* Section */
.section { margin-bottom: 32px; }
.section h2 { font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

/* Dashboard two-column lists */
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 600px) { .dash-cols { grid-template-columns: 1fr; } }
.dash-col-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px; }

/* Zones */
.zone-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.zone-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border); font-size: 14px; }
.zone-row:last-child { border-bottom: none; }
.zone-row:hover { background: var(--bg); }
.zone-row.current { background: color-mix(in srgb, var(--accent) 8%, transparent); font-weight: 600; }
.zone-row-badge { font-size: 11px; text-transform: uppercase; color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); padding: 2px 8px; border-radius: 10px; letter-spacing: 0.05em; }
.badge-current { font-size: 11px; text-transform: uppercase; color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); padding: 2px 8px; border-radius: 10px; letter-spacing: 0.05em; }

/* Projects */
.project-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.project-row { display: flex; align-items: center; padding: 12px 16px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border); }
.project-row:last-child { border-bottom: none; }
.project-row:hover { background: var(--bg); }
.project-row-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.project-row.done .project-row-title { color: var(--muted); text-decoration: line-through; }

/* Table */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.table th { text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table tr:last-child td { border-bottom: none; }
@media (hover: hover) { .table tr:hover td { background: var(--bg); } }
.table a { color: var(--accent); text-decoration: none; }
.table a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.badge-open { background: #fef3c7; color: var(--amber); }
.badge-done { background: #d1fae5; color: #065f46; }

/* Forms */
.form { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field input, .field textarea, .field select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus, .field select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 36px 40px; width: 360px; }
.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 28px; text-align: center; }
.login-card .field { margin-bottom: 16px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 10px; font-size: 15px; margin-top: 8px; }

/* Lease */
.lease-doc { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px 28px; font-size: 15px; line-height: 1.6; }
.lease-doc h2 { font-size: 15px; font-weight: 700; margin-top: 20px; margin-bottom: 8px; }
.lease-doc p { margin-bottom: 10px; }

/* Messages */
.message-board { max-width: 720px; margin: 0 auto 24px; display: flex; flex-direction: column; gap: 16px; }
.message { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; position: relative; }
.message-actions { position: absolute; top: 10px; right: 12px; display: flex; gap: 4px; }
.msg-action-btn { background: none; border: none; cursor: pointer; padding: 2px 4px; opacity: 0.4; line-height: 1; display: flex; align-items: center; font-size: 13px; color: inherit; }
.msg-action-btn svg { width: 14px; height: 14px; }
.msg-action-btn:hover { opacity: 1; }
.message-meta { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.message-author { font-weight: 600; font-size: 14px; }
.message-meta time { font-size: 11px; }
.message-content { font-size: 14px; line-height: 1.6; }
.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content a { color: var(--accent); }
.message-content strong { font-weight: 600; }
.message-content code { font-size: 12px; }
.message-content ul, .message-content ol { padding-left: 1.5em; margin-bottom: 8px; }
.message-content li { margin-bottom: 2px; }
.message-content blockquote { border-left: 3px solid var(--border); padding: 2px 10px; margin: 4px 0 8px; color: var(--muted); font-size: 13px; background: var(--bg); border-radius: 0 4px 4px 0; }
.message-content blockquote p { margin-bottom: 4px; }
.message-content blockquote strong { color: var(--text); }
.attachment { margin-top: 10px; }
.message-content + .attachment { margin-top: 18px; }
.message-footer { margin-top: 10px; display: flex; gap: 6px; justify-content: flex-end; }
.like-btn { background: none; border: 1px solid var(--border); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; font-size: 12px; color: var(--muted); line-height: 1; }
.like-btn:hover { background: var(--border); color: var(--text); }
.like-btn.liked { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.like-count { font-weight: 500; }
.attachment-thumb { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; display: block; cursor: zoom-in; }
.attachment:has(.attachment-thumb) { display: inline-block; margin-top: 28px; margin-right: 6px; vertical-align: top; }
.attachment-audio { display: block; width: 100%; margin-bottom: 4px; }
.attachment-file { font-size: 13px; color: var(--accent); text-decoration: none; }
.attachment-file:hover { text-decoration: underline; }

/* Lightbox */
.lightbox {
  display: none; position: fixed; inset: 0;
  z-index: 1100; background: rgba(0,0,0,0.85);
  align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox.open { display: flex; }
body:has(.lightbox.open) { overflow: hidden; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; object-fit: contain; cursor: default; }
.lightbox-nav {
  display: none; position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,0.5); color: #fff; border: none; cursor: pointer;
  width: 48px; height: 48px; border-radius: 50%; font-size: 32px; line-height: 1;
  align-items: center; justify-content: center; padding: 0 0 4px 0;
}
.lightbox-nav:hover { background: rgba(0,0,0,0.75); }
.lightbox-nav:disabled { opacity: 0.25; cursor: default; }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }

/* Compose */
.compose { max-width: 720px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; position: sticky; bottom: 16px; }
.compose-row { display: flex; align-items: flex-end; gap: 4px; }
.compose-row textarea { flex: 1; resize: none; border-color: transparent; background: var(--bg); overflow-y: hidden; min-height: 36px; line-height: 1.5; padding: 6px 8px; }
.compose-row textarea:focus { border-color: var(--accent); }
.compose-icon-btn { padding: 4px 6px; flex-shrink: 0; background: none; border: none; cursor: pointer; color: var(--muted); display: flex; align-items: center; }
.compose-icon-btn:hover { color: var(--accent); }
.compose-icon-btn.send { background: var(--accent); color: #fff; border-radius: 6px; padding: 5px 8px; }
.compose-icon-btn.send:hover { background: var(--accent-dark); color: #fff; }
.compose-icon-btn.send:disabled { opacity: 0.7; cursor: default; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Hide number input spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Utilities */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); background: #fee2e2; border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
code { font-family: ui-monospace, "SF Mono", monospace; font-size: 13px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 22px; font-weight: 700; margin-bottom: 24px; }

/* Settings sections */
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; margin-bottom: 24px; }
.settings-section h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
