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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
svg { display: block; }

/* ─── App Shell ────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
  height: 100vh;
  overflow: hidden;
}

/* ─── Top Bar ──────────────────────────────────────────────── */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.topbar-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }

/* View switcher */
.view-switcher {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.view-btn {
  padding: 4px 12px;
  border-radius: calc(var(--radius) - 2px);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.view-btn:hover { color: var(--text); background: var(--surface-3); }
.view-btn.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Audience toggle */
.audience-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
}

.audience-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s;
}

.audience-label:hover { color: var(--text); }

.audience-label.active-internal { color: var(--visibility-internal); }
.audience-label.active-external { color: var(--visibility-external); }

.audience-toggle-switch {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--surface-3);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.audience-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all 0.2s;
}

.audience-toggle-switch.internal {
  background: rgba(168, 85, 247, 0.2);
  border-color: var(--visibility-internal);
}
.audience-toggle-switch.internal::after {
  background: var(--visibility-internal);
  left: calc(100% - 14px);
}

.audience-toggle-switch.external {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--visibility-external);
}
.audience-toggle-switch.external::after {
  background: var(--visibility-external);
  left: 2px;
}

/* Topbar buttons */
.topbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.topbar-btn:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface-3);
}

.topbar-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.topbar-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.topbar-btn svg { width: 14px; height: 14px; }

/* ─── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 8px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}

.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: var(--accent-subtle); color: var(--accent-hover); }
.sidebar-item svg { width: 15px; height: 15px; flex-shrink: 0; }

.sidebar-item-count {
  margin-left: auto;
  font-size: 11px;
  background: var(--surface-3);
  border-radius: 10px;
  padding: 1px 6px;
  color: var(--text-muted);
}

.sidebar-spacer { flex: 1; }

/* ─── Main Content ─────────────────────────────────────────── */
#main {
  grid-area: main;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

/* ─── Loading & Empty States ───────────────────────────────── */
.state-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-muted);
}

.state-overlay .icon { font-size: 48px; opacity: 0.4; }
.state-overlay h3 { font-size: 18px; font-weight: 600; color: var(--text); }
.state-overlay p { font-size: 14px; max-width: 360px; text-align: center; }

/* ─── Shared Button Styles ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { background: var(--surface-3); border-color: var(--border-hover); }
.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.btn-danger { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
.btn.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

/* ─── Form Elements ────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.form-input,
.form-textarea,
.form-select {
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-select { cursor: pointer; }
.form-select option { background: var(--surface-2); }

/* ─── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-planned    { background: var(--status-planned-bg);    color: var(--status-planned); }
.badge-in-progress { background: var(--status-in-progress-bg); color: var(--status-in-progress); }
.badge-done       { background: var(--status-done-bg);       color: var(--status-done); }
.badge-cancelled  { background: var(--status-cancelled-bg);  color: var(--status-cancelled); }
.badge-external   { background: var(--visibility-external-bg); color: var(--visibility-external); }
.badge-internal   { background: var(--visibility-internal-bg); color: var(--visibility-internal); }

/* ─── Status menu (inline status picker) ──────────────────── */
.status-editable:hover { opacity: 0.8; }

.status-menu {
  z-index: 2000;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  min-width: 130px;
}

.status-menu-opt {
  all: unset;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.status-menu-opt:hover { opacity: 0.85; }
.status-menu-opt.active { outline: 2px solid currentColor; outline-offset: -2px; }

/* ─── Notification / Toast ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}

.toast.success { border-color: var(--status-done); }
.toast.error   { border-color: var(--priority-critical); }
.toast.warning { border-color: var(--priority-medium); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Conflict Banner ──────────────────────────────────────── */
#conflict-banner {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(234, 179, 8, 0.1);
  border-bottom: 1px solid rgba(234, 179, 8, 0.3);
  font-size: 13px;
  color: var(--priority-medium);
  z-index: 90;
}

#conflict-banner.visible { display: flex; }
#conflict-banner .conflict-actions { margin-left: auto; display: flex; gap: 8px; }

/* ─── Sync indicator ───────────────────────────────────────── */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-planned);
}

.sync-dot.syncing {
  background: var(--status-in-progress);
  animation: pulse 1s infinite;
}
.sync-dot.synced { background: var(--status-done); }
.sync-dot.error  { background: var(--priority-critical); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ─── Mobile / Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  /* Topbar: tighter layout */
  #topbar {
    gap: 6px;
    padding: 0 10px;
  }

  .topbar-title { max-width: 140px; font-size: 13px; }

  /* Hide sync indicator — not useful on mobile */
  .sync-indicator { display: none; }

  /* Audience toggle: hide emoji labels, keep switch */
  .audience-label { display: none; }
  .audience-toggle { padding: 4px 6px; }

  /* View switcher: tighter */
  .view-btn { padding: 4px 8px; font-size: 12px; }

  /* Topbar buttons: icon-only for secondary actions */
  #btn-import { display: none; }

  #btn-add,
  #btn-export {
    font-size: 0;        /* hides inline text node */
    padding: 6px 8px;
    gap: 0;
  }

  #btn-add svg,
  #btn-export svg {
    width: 16px;
    height: 16px;
  }

  .topbar-btn { padding: 5px 8px; font-size: 12px; }
  .topbar-sep { margin: 0; }
}

@media (max-width: 480px) {
  /* Extra-small: hide view switcher label text won't help much,
     but tighten everything further */
  .topbar-title { display: none; }
  .topbar-sep   { display: none; }
  #btn-settings,
  #btn-theme    { padding: 5px 6px; }
}
