/* ============ Tokens ============ */
:root {
  --sidebar-width: 260px;
  --topbar-height: 56px;
  --radius: 10px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #121316;
  --bg-elevated: #1b1d22;
  --bg-elevated-2: #23262d;
  --border: #2c2f37;
  --text: #f0f1f3;
  --text-muted: #9a9ea8;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --danger: #ff5c5c;
  --success: #36c275;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #eceef1;
  --border: #dadde2;
  --text: #1a1c20;
  --text-muted: #5f6470;
  --accent: #2e6ef0;
  --accent-text: #ffffff;
  --danger: #d6334a;
  --success: #1f9d58;
  --shadow: 0 4px 16px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============ Login ============ */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  width: 100%;
  max-width: 320px;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 28px;
  box-shadow: var(--shadow);
}

.login-logo {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 2px;
  margin: 0;
  color: var(--accent);
}

.login-subtitle {
  margin: 4px 0 32px;
  color: var(--text-muted);
  font-size: 14px;
}

.dev-mode-btn {
  margin-top: 10px;
  font-size: 13px;
}

.login-status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  transition: filter var(--transition), background var(--transition);
}

.btn .material-icons {
  font-size: 18px;
}

.btn-block { width: 100%; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { filter: brightness(0.95); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-elevated-2); }
.btn-icon .material-icons { font-size: 22px; }

/* ============ Shell layout ============ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.module-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20;
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--accent);
}

.sidebar-close { display: none; }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-elevated-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent);
  color: var(--accent-text);
}

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

.nav-group-header {
  margin-bottom: 2px;
}

.nav-caret {
  margin-left: auto;
  font-size: 18px;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.nav-group.open .nav-caret {
  transform: rotate(180deg);
}

.nav-sublist {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition);
}

.nav-group.open .nav-sublist {
  max-height: 200px;
}

.nav-sublist .nav-item {
  margin-top: 2px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.version-footer {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 4px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.sync-dot.offline { background: var(--danger); }
.sync-dot.syncing { background: #e0a73c; }

.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
}

/* ============ Páginas de módulo (lista/form/perfil) ============ */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-title .material-icons {
  font-size: 20px;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box input,
.form-group input,
.form-group textarea,
.form-group select,
.select-filter {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14.5px;
}

.form-group select,
.select-filter {
  cursor: pointer;
}

.search-box input {
  padding-left: 36px;
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input:focus,
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.select-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
  cursor: pointer;
}
.checkbox-inline input { cursor: pointer; }

.filters-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.select-filter {
  width: auto;
  cursor: pointer;
}

.loading-state,
.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 4px;
  text-align: center;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.list-item:hover {
  border-color: var(--accent);
  background: var(--bg-elevated-2);
}

.list-item-main { flex: 1; min-width: 0; }

.list-item-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-item-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-arrow {
  color: var(--text-muted);
  font-size: 20px;
  flex-shrink: 0;
}

.list-item-inactive {
  opacity: 0.5;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-muted { background: var(--bg-elevated-2); color: var(--text-muted); }
.badge-success { background: rgba(54,194,117,0.15); color: var(--success); }
.badge-danger { background: rgba(255,92,92,0.15); color: var(--danger); }

/* ============ Formulário ============ */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group textarea { resize: vertical; font-family: inherit; }

.form-group input:disabled,
.form-group textarea:disabled,
.form-group select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Mobile: empilha botões, largura total, ordem Salvar → Cancelar → Inativar → Excluir */
@media (max-width: 768px) {
  .form-actions {
    flex-direction: column;
  }
  .form-actions .btn {
    width: 100%;
  }
  .form-actions .btn-primary { order: 1; }
  .form-actions .btn-ghost { order: 2; }
  .form-actions .btn-secondary { order: 3; }
  .form-actions .btn-danger { order: 4; }
}

/* ============ Botões de ação em listagens (icon-only no mobile) ============ */
.action-btn .btn-label {
  white-space: nowrap;
}

@media (max-width: 768px) {
  .action-btn {
    padding: 8px;
  }
  .action-btn .btn-label {
    display: none;
  }
}

/* ============ Swipe to action (Clientes, Categorias, Catálogo) ============ */
.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

.swipe-actions .action-btn {
  border-radius: 0;
  height: 100%;
  width: 72px;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 8px;
}

.swipe-actions .action-btn .material-icons {
  font-size: 20px;
}

.swipe-content {
  position: relative;
  background: var(--bg-elevated);
  touch-action: pan-y;
  will-change: transform;
}

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--bg-elevated-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { filter: brightness(1.08); }

/* ============ Campos somente leitura (ex: Lixeira) ============ */
.profile-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
  margin-bottom: 16px;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14.5px;
}

.profile-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ============ Placeholder de módulo ============ */
.module-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  gap: 8px;
}
.module-placeholder .icon { font-size: 42px; }

/* ============ Mobile ============ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .menu-overlay.open { display: block; }
  #btn-open-menu { display: flex; }
}

@media (min-width: 769px) {
  #btn-open-menu { display: none; }
}

@media (max-width: 480px) {
  .page-header { flex-wrap: wrap; }
  .page-header .search-box { flex-basis: 100%; order: 1; }
  .page-header .btn-primary { order: 2; }
}

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: calc(100% - 32px);
  max-width: 380px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-clickable {
  cursor: pointer;
  pointer-events: auto;
  border-color: var(--accent);
}
.toast-clickable:hover { filter: brightness(1.1); }

.toast-icon { font-size: 20px; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: #e0a73c; }

/* ============ Modal de confirmação ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: 20px;
}

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-box-lg {
  max-width: 480px;
}

.modal-title {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 600;
}

.modal-message {
  margin: 0 0 20px;
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-confirm-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14.5px;
  margin-bottom: 20px;
}
.modal-confirm-input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:disabled:hover {
  filter: none;
}

/* ============ Abas ============ */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ============ Lixeira ============ */
.nav-item-trash {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  font-family: inherit;
}

.trash-group {
  margin-bottom: 24px;
}

.trash-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.trash-group-header .material-icons { font-size: 18px; }

.trash-item {
  flex-wrap: wrap;
  cursor: pointer;
}
.trash-item:hover {
  border-color: var(--accent);
  background: var(--bg-elevated-2);
}

.trash-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.trash-item-actions .btn {
  padding: 8px 12px;
  font-size: 13px;
}

.trash-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}
