/* Porter OS - Base Styles & Overrides */
:root {
  --os-granite: var(--granite);
  --os-limestone: var(--limestone);
  --os-ink: var(--ink);
  --os-line: var(--line);
  --os-shadow: rgba(21, 35, 59, 0.1);
  --os-hover: rgba(127, 127, 127, 0.1);
}

[data-theme="dark"], @media (prefers-color-scheme: dark) {
  :root {
    --os-shadow: rgba(0, 0, 0, 0.5);
  }
}

body, html {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: var(--font);
  background-color: var(--os-granite); color: var(--os-ink);
}

/* Boot Animation */
.os-boot {
  position: fixed; inset: 0; z-index: 10000;
  background-color: var(--os-granite);
  display: flex; align-items: center; justify-content: center;
  animation: bootFadeOut 0.2s 0.9s forwards ease-out;
}
.os-boot svg {
  width: 90px; color: var(--os-ink);
  animation: bootScale 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
@keyframes bootFadeOut { to { opacity: 0; visibility: hidden; } }
@keyframes bootScale { 0% { transform: scale(0.8); opacity: 0; } 20% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .os-boot { display: none !important; } }

/* Layout Grid */
.os-layout {
  display: flex; flex-direction: column; height: 100vh;
}
.os-topbar {
  height: 44px; background-color: var(--os-limestone); color: var(--os-ink);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 16px; border-bottom: 1px solid var(--os-line);
  font-size: 14px; z-index: 1000; flex-shrink: 0;
}
.os-topbar > div { display: flex; align-items: center; gap: 12px; }
.top-logo svg { height: 18px; width: auto; display: block; }
.top-title { font-size: 16px; font-weight: 600; }
.top-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.os-workspace {
  flex: 1; display: flex; position: relative; overflow: hidden;
}

/* Desktop Watermark */
.os-watermark {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 400px; max-width: 80%; color: var(--os-line);
  z-index: 0; pointer-events: none;
}
.os-watermark svg { width: 100%; height: auto; display: block; }

/* Desktop Widgets */
.os-widgets {
  width: 320px; background-color: var(--os-granite);
  border-left: 1px solid var(--os-line); padding: 24px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 24px; z-index: 10;
}
.os-widgets h2 { margin: 0 0 16px 0; font-size: 20px; }
.os-widget { background: var(--os-limestone); border: 1px solid var(--os-line); border-radius: 12px; padding: 16px; box-shadow: 0 2px 8px var(--os-shadow); }
.widget-number { font-size: 32px; font-weight: 800; font-stretch: 75%; margin: 0; }
.widget-label { margin: 4px 0 12px; font-size: 14px; opacity: 0.8; }
.widget-title { font-size: 14px; font-weight: 600; margin: 0 0 12px 0; }

.widget-breakdown { list-style: none; padding: 0; margin: 0; font-size: 13px; opacity: 0.9; }
.widget-breakdown li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--os-line); }
.widget-breakdown li:last-child { border: none; padding-bottom: 0; }
.widget-breakdown span { opacity: 0.7; }

.btn-need {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--os-granite); border: 1px solid var(--os-line); border-radius: 6px;
  padding: 10px; margin-bottom: 8px; font-family: inherit; color: inherit; font-size: 13px;
  cursor: pointer; transition: background 0.2s;
}
.btn-need:last-child { margin-bottom: 0; }
.btn-need:hover { background: var(--os-hover); }
.btn-need i { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

.timeline-list { list-style: none; padding: 0; margin: 0; font-size: 13px; position: relative; }
.timeline-list::before {
  content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px;
  width: 1px; background: var(--os-line);
}
.timeline-list li { position: relative; padding-left: 16px; margin-bottom: 12px; display: flex; flex-direction: column; }
.timeline-list li:last-child { margin-bottom: 0; }
.timeline-list li::before {
  content: ''; position: absolute; left: 1px; top: 6px; width: 7px; height: 7px; box-sizing: border-box;
  background: var(--os-limestone); border: 1px solid var(--os-ink); border-radius: 50%;
}
.timeline-list time { font-family: var(--mono); font-size: 11px; opacity: 0.6; line-height: 1; margin-bottom: 2px; }

/* Windows Container */
.os-windows {
  flex: 1; position: relative; z-index: 5;
}

/* Desktop Dock */
.os-dock {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background-color: var(--os-limestone); border: 1px solid var(--os-line);
  padding: 8px 12px; border-radius: 28px; display: flex; gap: 12px;
  box-shadow: 0 4px 24px var(--os-shadow); z-index: 5000;
}
.dock-btn {
  background: none; border: none; padding: 6px; cursor: pointer; position: relative;
  border-radius: 8px; transition: transform 0.2s, background 0.2s; outline: none;
}
.dock-btn:hover, .dock-btn:focus-visible { background: var(--os-hover); transform: translateY(-2px); }
.dock-btn svg { display: block; width: 28px; height: 42px; }
.dock-btn::after {
  content: ''; position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; background-color: var(--os-ink); border-radius: 50%; opacity: 0; transition: opacity 0.2s;
}
.dock-btn.is-open::after { opacity: 1; }

/* Windows */
.window {
  position: absolute; width: 420px; height: 520px;
  background-color: var(--os-limestone); border: 1px solid var(--os-line);
  border-radius: 12px; display: none; flex-direction: column;
  box-shadow: 0 12px 40px var(--os-shadow); overflow: hidden;
  transform-origin: bottom center; z-index: 100;
}
.window.win-large { width: 720px; height: 560px; }
#win-chats { width: 540px; height: 560px; }
#win-backroom { width: 520px; height: 460px; }

.window.is-open { display: flex; animation: winOpen 0.16s ease-out; }
@keyframes winOpen { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.window-titlebar {
  height: 44px; flex-shrink: 0; background-color: var(--os-limestone);
  border-bottom: 1px solid var(--os-line); display: flex; justify-content: space-between; align-items: center;
  padding: 0 12px; cursor: grab; user-select: none;
}
.window-titlebar:active { cursor: grabbing; }
.win-title { font-weight: 600; font-size: 14px; }
.win-controls { display: flex; gap: 8px; }
.win-controls button {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--os-line);
  background: transparent; color: var(--os-ink); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.win-controls button:hover { background: var(--os-hover); }
.win-back { display: none; background: none; border: none; font-size: 18px; color: var(--os-ink); padding: 0 12px; cursor: pointer; }

.window-body { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; position: relative; }

/* Mobile Logic */
.os-mobile-home { display: none; flex-direction: column; height: 100%; overflow-y: auto; padding: 16px; box-sizing: border-box; z-index: 10; }
.os-mobile-widgets { margin-bottom: 24px; display: flex; flex-direction: column; gap: 16px; }
.os-mobile-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; justify-items: center; }
.os-mobile-grid .dock-btn { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.os-mobile-grid .dock-btn::after { display: none; }
.os-mobile-grid .dock-btn span { font-size: 11px; font-weight: 600; text-align: center; }

@media (max-width: 899px) {
  .os-desktop-ui, .os-widgets, .os-dock, .top-status, .top-link, .os-watermark { display: none !important; }
  .os-mobile-home { display: flex; }
  .os-workspace { background-color: var(--os-granite); }
  .window {
    position: fixed; inset: 0; width: 100% !important; height: 100% !important; border-radius: 0;
    border: none; z-index: 10000 !important; animation: none;
  }
  .window-titlebar { cursor: default; height: 56px; border-radius: 0; justify-content: flex-start; gap: 16px; }
  .win-controls { display: none; }
  .win-back { display: block; }
  .chat-list { display: none; }
  .app-chats { flex-direction: column; }
  .app-prospects { overflow-x: auto; }
  .pipeline { padding-bottom: 16px; }
  .pipe-col { flex: 0 0 260px; }
  .app-backroom { flex-direction: column; }
  .br-term-container { min-height: 200px; flex: none; }
  .br-tasks { width: 100%; border-left: none; border-top: 1px solid var(--os-line); }
  .app-frontdesk { flex-direction: column; }
  .fd-left, .fd-right { width: 100%; border-right: none; }
  .fd-right { min-height: 400px; }
}

/* ------------------- Apps Internal ------------------- */
.app-chats { flex-direction: row; }
.chat-list { width: 220px; flex-shrink: 0; border-right: 1px solid var(--os-line); overflow-y: auto; }
.chat-item { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--os-line); cursor: pointer; }
.chat-item.is-active { background-color: var(--os-hover); }
.chat-item .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--door-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; flex-shrink: 0; }
.chat-info { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.chat-info b { font-size: 14px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.chat-info small { font-size: 12px; opacity: 0.7; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.chip { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; margin-top: 4px; width: fit-content; }
.chip-draft { background: var(--door-saffron); color: #000; }
.chip-porter { background: var(--os-granite); border: 1px solid var(--os-line); }
.chip-need { background: var(--door-red); color: #fff; }

.chat-thread-wrap { flex: 1; display: flex; flex-direction: column; background: #efeae2; min-width: 0; }
[data-theme="dark"] .chat-thread-wrap { background: #0b141a; }
.chat-thread { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.wa-msg { background: #fff; color: #111; padding: 6px 8px; border-radius: 8px; max-width: 85%; font-size: 14px; align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,0.1); position: relative; }
.wa-msg--out { background: #D9FDD3; align-self: flex-end; }
[data-theme="dark"] .wa-msg { background: #202c33; color: #fff; }
[data-theme="dark"] .wa-msg--out { background: #005C4B; }
.wa-msg__meta { font-size: 10px; opacity: 0.6; float: right; margin: 6px 0 -4px 8px; }
.wa-msg__ticks { color: #53bdeb; }

.draft-overlay { padding: 0 16px 16px; flex-shrink: 0; }
.draft-box { background: var(--os-limestone); border: 1px solid var(--os-line); border-radius: 12px; padding: 16px; box-shadow: 0 4px 12px var(--os-shadow); }
.draft-title { font-size: 12px; font-weight: bold; color: var(--door-saffron); margin-bottom: 8px; }
.draft-text { font-size: 14px; margin-bottom: 12px; }
.draft-actions { display: flex; gap: 8px; }

.app-prospects { padding: 16px; }
.pipeline { display: flex; gap: 16px; overflow-x: auto; height: 100%; padding-bottom: 8px; }
.pipe-col { flex: 0 0 260px; background: var(--os-granite); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; }
.pipe-col h4 { margin: 0 0 12px; font-size: 16px; }
.lead-card { background: var(--os-limestone); border: 1px solid var(--os-line); border-radius: 6px; padding: 12px; margin-bottom: 8px; box-shadow: 0 1px 3px var(--os-shadow); cursor: pointer; }
.lead-card b { display: block; margin-bottom: 6px; font-size: 14px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 10px; background: var(--os-granite); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--os-line); }

.app-backroom { flex-direction: row; }
.br-term-container { flex: 1; background: var(--backroom); position: relative; }
.br-tasks { width: 240px; padding: 16px; border-left: 1px solid var(--os-line); overflow-y: auto; flex-shrink: 0; }
.br-tasks h4 { margin: 0 0 16px; font-size: 16px; }
.br-task { margin-bottom: 16px; font-size: 13px; }
.br-task p { margin: 0 0 6px; opacity: 0.9; }
.progress { height: 6px; background: var(--os-granite); border-radius: 3px; overflow: hidden; }
.progress .bar { height: 100%; }
.bg-saffron { background: var(--door-saffron); }
.bg-green { background: var(--door-green); }
.bg-blue { background: var(--door-blue); }

.app-quotes, .app-team { overflow-x: auto; padding: 16px; }
.os-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.os-table th, .os-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--os-line); }
.os-table th { font-weight: 600; opacity: 0.7; }
.totals td { border-bottom: none; font-size: 15px; }
.chip-sm { padding: 2px 6px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.chip-paid { background: #D9FDD3; color: #005C4B; }
.chip-overdue { background: #ffe3e6; color: #B3262F; }
.chip-viewed { background: #e0f2fe; color: #0284c7; }
.chip-sent { background: var(--os-granite); border: 1px solid var(--os-line); }

.app-voice { padding: 20px; gap: 24px; }
.voice-section h4 { margin: 0 0 12px; font-size: 16px; }
.voice-section label { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 8px; }
progress { width: 120px; height: 8px; border-radius: 4px; overflow: hidden; }
progress::-webkit-progress-bar { background-color: var(--os-granite); }
progress::-webkit-progress-value { background-color: var(--door-plum); }
.compare-box { background: var(--os-granite); padding: 12px; border-radius: 8px; font-size: 13px; border: 1px solid var(--os-line); }
.compare-box p { margin: 0 0 8px; }
.compare-box p:last-child { margin: 0; }

.app-frontdesk { flex-direction: row; }
.fd-left { flex: 1; padding: 20px; overflow-y: auto; border-right: 1px solid var(--os-line); }
.fd-left h4 { margin: 0 0 16px; font-size: 16px; }
.fd-left ul { padding-left: 16px; font-size: 14px; margin-bottom: 24px; }
.fd-left li { margin-bottom: 8px; }
.fd-right { width: 300px; background: #000; position: relative; flex-shrink: 0; }
.ai-toggle { display: flex; align-items: center; gap: 12px; font-size: 14px; margin-bottom: 16px; }
.switch { width: 36px; height: 20px; border-radius: 10px; background: var(--os-line); border: none; position: relative; cursor: pointer; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left 0.2s; }
.switch.is-on { background: var(--door-green); }
.switch.is-on::after { left: 18px; }
.hint { font-size: 12px; opacity: 0.7; font-style: italic; }

.app-integrations { padding: 20px; display: flex; flex-direction: column; gap: 24px; }
.int-group h4 { margin: 0 0 12px; font-size: 16px; border-bottom: 1px solid var(--os-line); padding-bottom: 4px; }
.int-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; padding: 8px 0; }

.app-team p { font-size: 14px; margin-top: 0; margin-bottom: 16px; opacity: 0.9; }

.app-privacy { padding: 20px; display: flex; flex-direction: column; gap: 16px; font-size: 14px; }
.app-privacy p { margin: 0; }
.priv-toggles { background: var(--os-granite); padding: 8px 16px; border-radius: 8px; border: 1px solid var(--os-line); }
.priv-list { margin: 0; padding-left: 16px; }
.priv-actions { margin-top: 8px; }
.forget-zone { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--os-line); }
#forget-confirm { margin-top: 12px; display: flex; align-items: center; gap: 12px; }
#forget-done { margin-top: 12px; color: var(--door-green); font-weight: bold; }

/* safety: the boot screen never blocks the desktop, even if a script fails */
.os-boot{animation:os-boot-out .25s 1.4s forwards}
@keyframes os-boot-out{to{opacity:0;visibility:hidden;pointer-events:none}}
