/* ============================================================
   app.css — Shell, sidebar, topbar, layout, responsive.
   Uses only tokens from theme.css. No raw color values.
   ============================================================ */

/* ── Global reset ─────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

::selection { background: var(--accent-soft); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

/* Prevent auto-zoom on iOS for all inputs */
input, select, textarea { font-size: 16px; }
@media (min-width: 768px) {
  input, select, textarea { font-size: 14px; }
}

/* ── App shell ────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Backdrop (mobile overlay) ────────────────────────────── */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 42, 38, 0.45);
  z-index: 300;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.backdrop.show {
  display: block;
  opacity: 1;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 100;
  transition: width 0.25s ease;
  padding-top: var(--sat);
  padding-left: var(--sal);
}

.sidebar::-webkit-scrollbar          { width: 3px; }
.sidebar::-webkit-scrollbar-track    { background: transparent; }
.sidebar::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 3px; }

/* Sidebar brand header */
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  background: var(--accent);
  color: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-brand-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.sidebar-brand-name em {
  font-style: normal;
  color: var(--accent);
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.03em;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 10px 4px;
  margin-top: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-xs);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 450;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  position: relative;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--bg-warm);
  color: var(--ink);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 550;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar footer — current user + logout */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  padding-bottom: calc(12px + var(--sab));
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.sidebar-user-info strong {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-info small {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  color: var(--muted);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.sidebar-logout-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ── Avatar ───────────────────────────────────────────────── */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  font-family: var(--font-ui);
}

.av-coral   { background: var(--accent-soft); color: var(--accent-deep); }
.av-blue    { background: var(--info-soft);   color: var(--info); }
.av-amber   { background: var(--warn-soft);   color: var(--warn); }
.av-green   { background: var(--success-soft);color: var(--success); }
.av-neutral { background: var(--bg-warm);     color: var(--ink-2); }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.main-content::-webkit-scrollbar       { width: 5px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }

/* Page content padding */
.page-body {
  padding: 24px 28px 40px;
  flex: 1;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar-title h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title h1 em {
  font-style: normal;
  color: var(--accent);
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
}

/* Topbar search */
.topbar-search {
  position: relative;
  flex: 0 1 280px;
  min-width: 0;
}

.topbar-search .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}

.topbar-search input[type="search"] {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 13px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
}

.topbar-search input[type="search"]:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Hamburger */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-xs);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 20px;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.12s;
}

.hamburger-btn:hover { background: var(--bg-warm); }

/* ── Buttons global tweaks ────────────────────────────────── */
.btn {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:active { transform: scale(0.98); }

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

.btn-primary:hover, .btn-primary:focus {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
}

.btn-outline-secondary {
  border-color: var(--border-strong);
  color: var(--ink-2);
  background: transparent;
}

.btn-outline-secondary:hover {
  background: var(--bg-warm);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn-outline-danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn-outline-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-whatsapp {
  background: #25D366;
  border-color: #25D366;
  color: #fff;
}

.btn-whatsapp:hover { background: #1ebe5d; border-color: #1ebe5d; color: #fff; }

/* ── Form actions bar (bottom of form pages) ──────────────── */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 0 8px;
}

/* Inline active-status toggle, sits on the left of form-actions */
.form-status-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  user-select: none;
}

/* Simple measurement checkbox list (item-edit mapping section) */
.meas-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface);
  transition: border-color .12s, background .12s, color .12s;
  width: 100%;
}

.meas-check-item:hover { border-color: var(--accent); background: var(--accent-soft); }

.meas-check-item.is-checked {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 500;
}

.meas-check-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ── Font utility classes ─────────────────────────────────── */
.font-display { font-family: var(--font-display); }
.font-mono    { font-family: var(--font-mono); }
.font-ui      { font-family: var(--font-ui); }

/* ── Atelier link ─────────────────────────────────────────── */
.atelier-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.atelier-link:hover { color: var(--accent-deep); text-decoration: underline; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1100px) {
  .page-body { padding: 20px 20px 32px; }
  .topbar    { padding: 0 18px; }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-width-mobile));
    top: 0;
    width: var(--sidebar-width-mobile);
    height: 100%;
    z-index: 400;
    transition: left 0.25s cubic-bezier(.4,0,.2,1);
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: var(--shadow-lg);
  }

  .hamburger-btn { display: flex; }
  .topbar { padding: 0 14px; }
  .page-body { padding: 16px 16px 32px; }
}

@media (max-width: 640px) {
  .topbar-title h1 { font-size: 18px; }
  .topbar-search   { flex: 1 1 100%; order: 10; min-width: 0; }
  .topbar          { flex-wrap: wrap; height: auto; padding: 10px 14px; row-gap: 8px; }
}

@media (max-width: 480px) {
  .btn-text { display: none; }

  .topbar .btn {
    padding-left: 9px;
    padding-right: 9px;
  }
}
