/* InventTasks web — Obsidian environment emulation.
   Part 1: the CSS custom properties the plugin's styles.css consumes
   (it maps them onto --it-* tokens itself, see styles.css :root block).
   Part 2: base widgets Obsidian normally styles (modal, settings, notices,
   prompt, form controls) — only what the plugin relies on. */

/* ---------- 1. Obsidian variables ---------- */

body {
  /* light (default) */
  --background-primary: #ffffff;
  --background-secondary: #f6f6f7;
  --background-modifier-border: #e2e2e4;
  --background-modifier-hover: rgba(0, 0, 0, 0.06);
  --background-modifier-active-hover: rgba(0, 0, 0, 0.1);
  --text-normal: #222426;
  --text-muted: #5c5f63;
  --text-faint: #9b9ea3;
  --text-error: #e93147;
  --text-on-accent: #ffffff;
  --interactive-accent: #7c5cff;
  --font-interface: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-monospace: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --navbar-height: 0px;
  --mobile-navbar-height: 0px;
  --icon-size: 18px;
}

body.theme-dark {
  --background-primary: #1e1e1e;
  --background-secondary: #252526;
  --background-modifier-border: #3f3f46;
  --background-modifier-hover: rgba(255, 255, 255, 0.06);
  --background-modifier-active-hover: rgba(255, 255, 255, 0.1);
  --text-normal: #dcddde;
  --text-muted: #9b9ea4;
  --text-faint: #6e7177;
  --text-error: #fb464c;
  --text-on-accent: #ffffff;
  --interactive-accent: #8a6cff;
}

/* ---------- 2. Shell ---------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-interface);
  font-size: 15px;
  background: var(--background-primary);
  color: var(--text-normal);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.it-web-view-host {
  flex: 1;
  min-height: 0;
  display: flex;
  min-width: 0;
}

/* Right-side Favorites panel — hidden until toggled (or auto-opened when the
   "right" bucket has favorites). The plugin's own .it-fav-panel styles render
   its contents; this just sizes the dock. */
.it-web-right-panel {
  flex: 0 0 260px;
  min-width: 0;
  border-left: 1px solid var(--background-modifier-border);
  background: var(--background-secondary);
  overflow: auto;
  display: none;
}
.it-web-view-host.it-web-right-open .it-web-right-panel { display: block; }

.it-web-icon-toggle { display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px; }
.it-web-icon-toggle .svg-icon { width: 16px; height: 16px; }
.it-web-icon-toggle.is-active {
  background: color-mix(in srgb, var(--interactive-accent) 16%, transparent);
  border-color: var(--interactive-accent);
  color: var(--interactive-accent);
}

/* Explorer (left navigator) toggle — hide the embedded sidebar on desktop.
   .it-layout is a 2-column grid (260px sidebar + 1fr main); just display:none-ing
   the sidebar leaves its 260px track empty and the main view collapses into it,
   so we ALSO drop the grid to a single column (the plugin's own "sidebar-docked"
   behaviour). Targeting a descendant of the host survives .it-layout re-renders.
   On mobile the sidebar is a separate overlay driven by the view's hamburger,
   so this never applies there. */
body:not(.is-mobile) .it-web-view-host.it-web-explorer-hidden .it-layout { grid-template-columns: 1fr; }
body:not(.is-mobile) .it-web-view-host.it-web-explorer-hidden .it-sidebar-wrap { display: none; }

@media (max-width: 600px) {
  /* On phones the panel overlays from the right instead of squeezing the view. */
  .it-web-right-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(80vw, 320px);
    z-index: 50;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
    padding-top: var(--safe-area-inset-top);
  }
}

.workspace-leaf-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.view-content {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.it-web-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  padding-top: calc(6px + var(--safe-area-inset-top));
  background: var(--background-secondary);
  border-bottom: 1px solid var(--background-modifier-border);
  flex: 0 0 auto;
}

.it-web-topbar-brand { font-weight: 700; }

.it-web-topbar-ws {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--background-modifier-hover);
  color: var(--text-muted);
}

.it-web-sync-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--background-modifier-hover);
  color: var(--text-muted);
}
.it-web-sync-status.is-idle {
  background: color-mix(in srgb, #2e9e5b 16%, transparent);
  color: #2e9e5b;
}
.it-web-sync-status.is-syncing {
  background: color-mix(in srgb, var(--interactive-accent) 18%, transparent);
  color: var(--interactive-accent);
}
.it-web-sync-status.is-error {
  background: color-mix(in srgb, var(--text-error) 15%, transparent);
  color: var(--text-error);
}
.it-web-sync-status.is-blocked {
  background: color-mix(in srgb, #e6a700 18%, transparent);
  color: #b58500;
}

.it-web-boot {
  margin: auto;
  color: var(--text-muted);
}

/* ---------- 3. Login ---------- */

.it-web-login {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.it-web-login-card {
  width: 360px;
  max-width: 100%;
  background: var(--background-secondary);
  border: 1px solid var(--background-modifier-border);
  border-radius: 14px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.it-web-login-title { font-size: 22px; font-weight: 700; }
.it-web-login-sub { color: var(--text-muted); margin-bottom: 6px; }
.it-web-login-error {
  color: var(--text-error);
  font-size: 13px;
  background: color-mix(in srgb, var(--text-error) 12%, transparent);
  border-radius: 8px;
  padding: 8px 10px;
}
.it-web-login-field { display: flex; flex-direction: column; gap: 4px; }
.it-web-login-field label { font-size: 12px; color: var(--text-muted); }
.it-web-login-card button { margin-top: 8px; }

/* ---------- 4. Form controls (Obsidian-like) ---------- */

button {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid var(--background-modifier-border);
  background: var(--background-primary);
  color: var(--text-normal);
  cursor: pointer;
}
button:hover { background: var(--background-modifier-hover); }
button.mod-cta {
  background: var(--interactive-accent);
  border-color: transparent;
  color: var(--text-on-accent);
  font-weight: 600;
}
button.mod-cta:hover { filter: brightness(1.08); }
button.mod-warning {
  background: var(--text-error);
  border-color: transparent;
  color: #fff;
}
button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--background-modifier-border);
  background: var(--background-primary);
  color: var(--text-normal);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--interactive-accent) 55%, transparent);
  outline-offset: -1px;
}

.svg-icon {
  width: var(--icon-size);
  height: var(--icon-size);
  stroke-width: 2;
  display: block;
  flex-shrink: 0;
}

.clickable-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.clickable-icon:hover { background: var(--background-modifier-hover); color: var(--text-normal); }

/* Toggle (Setting.addToggle) */
.checkbox-container {
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--background-modifier-border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.checkbox-container::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.checkbox-container.is-enabled { background: var(--interactive-accent); }
.checkbox-container.is-enabled::after { transform: translateX(18px); }
.checkbox-container.is-disabled { opacity: 0.5; cursor: default; }

/* ---------- 5. Modals ---------- */

.modal-container {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal {
  position: relative;
  background: var(--background-primary);
  border: 1px solid var(--background-modifier-border);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  padding: 18px 22px;
  min-width: 320px;
  max-width: min(720px, 92vw);
  max-height: 86vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 10px; padding-right: 24px; }
.modal-content { flex: 1; min-height: 0; }

.modal-close-button {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close-button::before { content: "\00d7"; font-size: 18px; line-height: 1; }
.modal-close-button:hover { background: var(--background-modifier-hover); color: var(--text-normal); }

@media (max-width: 600px) {
  .modal-container { padding: 0; align-items: stretch; }
  .modal {
    max-width: 100vw;
    width: 100vw;
    max-height: 100%;
    border-radius: 0;
    border: none;
    padding-bottom: calc(18px + var(--safe-area-inset-bottom));
  }
}

/* ---------- 6. Settings rows ---------- */

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
  border-top: 1px solid var(--background-modifier-border);
}
.setting-item:first-child { border-top: none; }
.setting-item-info { flex: 1; min-width: 0; }
.setting-item-name { font-size: 14px; font-weight: 500; }
.setting-item-description { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.setting-item-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.setting-item-heading { border-top: none; }
.setting-item-heading .setting-item-name { font-size: 15px; font-weight: 700; }
.setting-item.is-disabled { opacity: 0.55; }

/* ---------- 7. Prompt (SuggestModal) ---------- */

.modal.prompt { padding: 10px; width: min(560px, 92vw); }
.prompt-input-container { display: flex; }
.prompt-input { width: 100%; font-size: 15px; padding: 10px 12px; }
.prompt-results { margin-top: 8px; max-height: 55vh; overflow: auto; }
.suggestion-item { padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.suggestion-item.is-selected { background: var(--background-modifier-hover); }
.suggestion-empty { padding: 14px; color: var(--text-muted); text-align: center; }

/* ---------- 8. Notices ---------- */

.notice-container {
  position: fixed;
  top: calc(12px + var(--safe-area-inset-top));
  right: 12px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 24px));
}

.notice {
  background: var(--background-secondary);
  border: 1px solid var(--background-modifier-border);
  border-radius: 9px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  padding: 10px 14px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: pre-wrap;
}

/* ---------- 9. Markdown output (MarkdownRenderer shim) ---------- */

.modal-content :is(p, ul, ol) { margin: 0.4em 0; }
.modal-content pre {
  font-family: var(--font-monospace);
  background: var(--background-secondary);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
}
.modal-content code { font-family: var(--font-monospace); font-size: 0.9em; }
