:root {
  --brown:       #2E1E14;
  --brown-mid:   #4A2E1E;
  --brown-light: #6B4333;
  --cream:       #DBBFA0;
  --cream-light: #F2E8DF;
  --cream-pale:  #FAF5F0;
  --text-dark:   #1C1008;
  --text-mid:    #5C3D2A;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; height: 100vh; overflow: hidden; background: var(--cream-pale); }

/* =====================
   LOGIN / LANDING
   ===================== */
#landing-screen, #user-login-screen, #login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--brown); padding: 16px;
}
.login-box {
  background: white; padding: 36px 32px; border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35); text-align: center;
  width: 100%; max-width: 340px;
}
.login-logo {
  width: 90px; height: 90px; border-radius: 50%;
  overflow: hidden; margin: 0 auto 14px;
}
.login-logo img { width: 100%; height: 100%; object-fit: cover; }
.login-box h1   { color: var(--brown); font-size: 24px; margin-bottom: 2px; }
.login-box p    { color: var(--text-mid); margin-bottom: 22px; font-size: 13px; }
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1.5px solid #e0d6ce; border-radius: 8px; font-size: 15px;
  font-family: inherit;
}
.login-box input:focus {
  outline: none; border-color: var(--brown-mid);
  box-shadow: 0 0 0 3px var(--cream-light);
}
.login-box > button, #admin-login-inline > button:first-of-type,
#user-login-screen .login-box > button:first-of-type {
  width: 100%; padding: 13px; background: var(--brown); color: white;
  border: none; border-radius: 8px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: background 0.2s; margin-bottom: 8px;
}
.login-box > button:hover { background: var(--brown-mid); }
.btn-evangel {
  width: 100%; padding: 14px; background: var(--brown); color: white;
  border: none; border-radius: 8px; font-size: 16px; font-weight: 600;
  cursor: pointer; margin-bottom: 10px; transition: background 0.2s;
}
.btn-evangel:hover { background: var(--brown-mid); }
.btn-admin-link {
  width: 100%; padding: 10px; background: none; color: var(--text-mid);
  border: 1.5px solid #e0d6ce; border-radius: 8px; font-size: 14px; cursor: pointer;
  transition: all 0.15s;
}
.btn-admin-link:hover { border-color: var(--brown-light); color: var(--brown); }
.btn-back {
  width: 100%; padding: 8px; background: none; border: none;
  color: #aaa; font-size: 13px; cursor: pointer; margin-top: 2px;
  text-decoration: underline;
}
#admin-login-inline input { margin-top: 8px; }
.error-msg { color: #b03a2e; margin-top: 8px; font-size: 13px; }

/* =====================
   APP LAYOUT
   ===================== */
#app-screen { display: flex; height: 100vh; position: relative; }
.hidden { display: none !important; }

/* =====================
   SIDEBAR — Desktop
   ===================== */
#sidebar {
  width: 300px; min-width: 300px; background: white;
  box-shadow: 2px 0 8px rgba(0,0,0,0.12); overflow-y: auto;
  display: flex; flex-direction: column; z-index: 1000;
  transition: transform 0.3s ease;
}
#sidebar-header {
  background: var(--brown); color: var(--cream); padding: 14px 16px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 1;
}
#sidebar-header h2  { flex: 1; font-size: 17px; color: var(--cream); }
#current-user-label { font-size: 12px; opacity: 0.8; }
#admin-panel, #user-panel { padding: 14px; }
h3 { color: var(--brown); font-size: 14px; margin-bottom: 10px; }

/* =====================
   MOBILE TOGGLE BUTTON
   ===================== */
#sidebar-toggle {
  display: flex;
  position: absolute; top: 12px; left: 12px; z-index: 1100;
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--brown); color: var(--cream);
  border: none; font-size: 22px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  align-items: center; justify-content: center;
}
#sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 999;
}
#sidebar-overlay.active { display: block; }

/* =====================
   BUTTONS
   ===================== */
button { cursor: pointer; }
.btn-full {
  width: 100%; padding: 11px; background: var(--brown); color: white;
  border: none; border-radius: 8px; font-size: 14px; margin-bottom: 8px;
  transition: background 0.2s; font-weight: 600;
}
.btn-full:hover { background: var(--brown-mid); }
.btn-primary { background: #2e7d32; color: white; border: none; border-radius: 6px; padding: 8px 14px; font-weight: 600; }
.btn-primary:hover { background: #1b5e20; }
.btn-danger  { background: #b03a2e !important; }
.btn-danger:hover { background: #922b21 !important; }
.btn-sm {
  padding: 5px 11px; background: rgba(255,255,255,0.18); color: var(--cream);
  border: 1px solid rgba(219,191,160,0.45); border-radius: 6px; font-size: 12px;
}
.btn-sm:hover { background: rgba(255,255,255,0.3); }
.btn-link { background: none; border: none; color: #aaa; font-size: 13px; margin-top: 4px; text-decoration: underline; }
.btn-row  { display: flex; gap: 8px; margin-top: 8px; }
.btn-row button { flex: 1; padding: 9px; border: 1px solid #ccc; border-radius: 6px; background: #f5f5f5; font-size: 13px; }

/* =====================
   FORMS
   ===================== */
.panel-form {
  background: var(--cream-pale); border: 1px solid var(--cream);
  border-radius: 10px; padding: 12px; margin-bottom: 12px;
}
.panel-form input, .panel-form textarea {
  width: 100%; padding: 9px 11px; margin-bottom: 8px;
  border: 1.5px solid #e0d6ce; border-radius: 7px;
  font-size: 14px; font-family: inherit;
}
.panel-form input:focus, .panel-form textarea:focus {
  outline: none; border-color: var(--brown-mid);
  box-shadow: 0 0 0 2px var(--cream-light);
}
.panel-form textarea { height: 60px; resize: vertical; }
.hint {
  font-size: 12px; color: var(--text-mid); background: var(--cream-light);
  border-radius: 6px; padding: 7px 9px; margin-bottom: 8px; line-height: 1.4;
}
#draw-status, #zone-draw-status { font-size: 13px; color: #555; margin-bottom: 6px; }

/* =====================
   PROJECT CARDS
   ===================== */
.project-card {
  border: 1.5px solid #e8e0d8; border-radius: 10px; padding: 11px 12px;
  margin-bottom: 8px; cursor: pointer; transition: all 0.15s;
}
.project-card:hover  { border-color: var(--brown-light); background: var(--cream-pale); }
.project-card.active { border-color: var(--brown); background: var(--cream-light); }
.project-card h4 { font-size: 14px; color: var(--text-dark); font-weight: 600; }
.project-card p  { font-size: 12px; color: #777; margin-top: 2px; }
.card-actions    { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card-actions button {
  font-size: 12px; padding: 5px 10px; border-radius: 6px;
  border: 1.5px solid #ddd; background: white; flex: 1;
}
.card-actions button:hover { background: var(--cream-pale); }
.card-actions .del-btn { color: #b03a2e; border-color: #f5c6c6; background: #fff5f5; }

/* =====================
   MAP
   ===================== */
#map { flex: 1; z-index: 1; }

/* =====================
   MODE SELECTOR
   ===================== */
.mode-selector { display: flex; gap: 6px; margin: 10px 0 8px; }
.mode-btn {
  flex: 1; padding: 9px 4px; border: 2px solid #ddd; border-radius: 8px;
  background: white; font-size: 12px; font-weight: 600; color: #666;
  transition: all 0.15s; cursor: pointer;
}
.mode-btn.active       { border-color: var(--brown); background: var(--cream-light); color: var(--brown); }
.mode-btn:hover:not(.active) { border-color: var(--cream); background: var(--cream-pale); }

/* =====================
   ZONE CHIPS
   ===================== */
.zone-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 4px; }
.zone-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px;
  border: 1.5px solid; border-radius: 12px; background: white;
}
.zone-chip button {
  background: none; border: none; padding: 0; font-size: 11px;
  line-height: 1; cursor: pointer; opacity: 0.7;
}
.zone-chip button:hover { opacity: 1; }

/* =====================
   ZONE LABEL ON MAP
   ===================== */
.zone-label {
  background: transparent; border: none; box-shadow: none;
  font-weight: 700; font-size: 13px; color: var(--brown);
  text-shadow: 0 0 4px white, 0 0 4px white, 0 0 4px white;
  white-space: nowrap; pointer-events: none;
}

/* =====================
   DRAWING ACTION BARS
   ===================== */
#line-drawing-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: var(--brown);
  color: var(--cream);
  border-radius: 14px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  font-size: 13px;
  white-space: nowrap;
  max-width: 92vw;
}
#line-drawing-bar.hidden { display: none !important; }

#line-drawing-bar button {
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#line-drawing-bar button:first-of-type { background: #4caf50; color: white; }
#line-drawing-bar button:last-of-type  { background: rgba(255,255,255,0.15); color: var(--cream); }

/* =====================
   CURSORS
   ===================== */
.leaflet-container.drawing   { cursor: crosshair !important; }
.leaflet-container.free-draw { cursor: crosshair !important; }

/* =====================
   API ERROR BANNER
   ===================== */
#api-error-banner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #b03a2e; color: white; padding: 12px 18px; border-radius: 10px;
  font-size: 13px; z-index: 9999; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  display: flex; align-items: center; gap: 12px; max-width: 90vw; text-align: left;
}
#api-error-banner button {
  background: white; color: #b03a2e; border: none; border-radius: 6px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}

/* Mobile top bar — always visible over map on mobile */
#mobile-top-bar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 1150;
  background: var(--brown); color: var(--cream);
  height: 52px; padding: 0 12px;
  align-items: center; gap: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
#mobile-top-bar h2 { font-size: 15px; color: var(--cream); flex: 1; }
#active-project-bar {
  display: none;
  font-size: 13px; font-weight: 600; color: var(--cream);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}
#active-project-bar.visible { display: block; }
#mobile-top-bar button {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(219,191,160,0.4);
  color: var(--cream); border-radius: 8px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
/* =====================
   MOBILE TOOLBAR
   ===================== */
#mobile-toolbar {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(calc(-50% + 150px)); /* center in map area (sidebar=300px) */
  z-index: 1140;
  background: rgba(46,30,20,0.88);
  padding: 6px 10px;
  gap: 8px;
  display: flex;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
#mobile-toolbar.hidden { display: none !important; }
.tool-btn {
  padding: 7px 16px;
  border: 2px solid rgba(219,191,160,0.3);
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.tool-btn.active {
  background: var(--cream-light);
  color: var(--brown);
  border-color: var(--cream);
}

@media (max-width: 768px) {
  #mobile-top-bar { display: flex; }
  #map { padding-top: 96px; }
  #sidebar-toggle { display: none; }
  #mobile-toolbar {
    top: 52px;
    left: 0; right: 0;
    transform: none;
    border-radius: 0;
    box-shadow: none;
    justify-content: center;
  }
}

/* Hide toggle on desktop (sidebar always visible) */
@media (min-width: 769px) {
  #sidebar-toggle  { display: none; }
  #sidebar-overlay { display: none !important; }
}

/* =====================
   MOBILE  (≤ 768px)
   ===================== */
@media (max-width: 768px) {

  /* Sidebar becomes a bottom sheet */
  #sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100%; min-width: unset;
    height: 70vh; max-height: 70vh;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
    transform: translateY(100%);
    z-index: 1000;
  }
  #sidebar.open { transform: translateY(0); }

  /* Drag handle at top of sheet */
  #sidebar-header::before {
    content: '';
    display: block; width: 40px; height: 4px;
    background: rgba(219,191,160,0.5); border-radius: 2px;
    margin: 0 auto 10px; flex-basis: 100%;
  }
  #sidebar-header {
    border-radius: 20px 20px 0 0;
    flex-wrap: wrap; padding: 10px 16px 12px;
  }

  /* toggle already visible globally */

  /* Map fills whole screen */
  #app-screen { flex-direction: column; }
  #map { width: 100%; height: 100vh; }

  /* Login box adjustments */
  .login-box { padding: 28px 22px; }

  /* Bigger tap targets */
  .mode-btn   { padding: 11px 4px; font-size: 13px; }
  .btn-full   { padding: 13px; font-size: 15px; }
  .card-actions button { padding: 8px 6px; font-size: 13px; }
  .project-card { padding: 13px 14px; }
  h3 { font-size: 15px; }
}
