/* Mia OS — terminal-luxe noir */
:root {
  --ink: #0c0e12;
  --ink-2: #12151c;
  --ink-3: #1a1e27;
  --line: #262c38;
  --text: #e8e6df;
  --text-dim: #8a8f9c;
  --accent: #e8a33d;       /* warm amber */
  --accent-soft: rgba(232, 163, 61, .14);
  --ok: #6fc28b;
  --warn: #e0635b;
  --radius: 14px;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-display);
  background:
    radial-gradient(1200px 700px at 75% -10%, rgba(232,163,61,.07), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(111,194,139,.05), transparent 55%),
    var(--ink);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
button { font-family: inherit; cursor: pointer; }
svg { display: block; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  min-height: 100dvh; padding: 24px; z-index: 100;
}
.login-card {
  width: min(360px, 100%); text-align: center;
  padding: 44px 32px; border: 1px solid var(--line);
  border-radius: 20px; background: var(--ink-2);
}
.login-logo { width: 56px; margin: 0 auto 18px; }
.login-card h1 { font-weight: 600; font-size: 28px; letter-spacing: .5px; }
.login-sub { color: var(--text-dim); font-size: 12px; margin: 6px 0 26px; }
.login-card input {
  width: 100%; padding: 13px 16px; font-size: 16px;
  background: var(--ink); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.login-card input:focus-visible { border-color: var(--accent); }
.login-card button {
  width: 100%; margin-top: 12px; padding: 13px;
  font-size: 15px; font-weight: 600;
  background: var(--accent); color: #1c1405;
  border: none; border-radius: 10px;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card button:active { transform: translateY(1px); }
.login-err { color: var(--warn); font-size: 13px; margin-top: 12px; }

/* ---------- shell layout ---------- */
.shell { display: flex; flex-direction: column; height: 100dvh; }

.menubar {
  display: flex; align-items: center; gap: 14px;
  height: 42px; padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: rgba(12,14,18,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0; z-index: 50;
}
.menubar-home {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--text);
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  padding: 6px 8px; border-radius: 8px; min-height: 32px;
}
.menubar-home:hover { background: var(--accent-soft); }
.menubar-home svg { width: 17px; height: 17px; color: var(--accent); }
.menubar-app { color: var(--text-dim); font-size: 12px; flex: 1; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menubar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.menubar-stat { font-size: 11px; color: var(--text-dim); }
.menubar-clock { font-size: 12px; color: var(--text); }
.menubar-icon {
  background: none; border: none; color: var(--text-dim);
  padding: 6px; border-radius: 8px; min-width: 32px; min-height: 32px;
}
.menubar-icon:hover { color: var(--text); background: var(--accent-soft); }
.menubar-icon svg { width: 16px; height: 16px; margin: auto; }

.desktop { position: relative; flex: 1; overflow: hidden; }

/* ---------- homescreen ---------- */
.home {
  height: 100%; overflow-y: auto; padding: 34px clamp(18px, 5vw, 64px) 120px;
}
.home-head { margin-bottom: 26px; }
.home-date { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; }
.home-greet { font-size: clamp(26px, 4.5vw, 40px); font-weight: 600; margin-top: 6px; }

.widgets {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  max-width: 760px; margin-bottom: 38px;
}
.widget {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--ink-2); padding: 16px 18px;
}
.widget h3 {
  font-size: 11px; font-weight: 500; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: 12px;
  font-family: var(--font-mono);
}
.widget .big { font-size: 26px; font-weight: 600; }
.widget .sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.meter { height: 5px; background: var(--ink); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .6s ease; }
.meter.ok > span { background: var(--ok); }
.meter.warn > span { background: var(--warn); }

.app-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-width: 980px;
}
.app-tile {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 16px; min-height: 64px;
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text); text-align: left;
  transition: border-color .15s, transform .15s;
}
.app-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.app-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-tile:active { transform: scale(.98); }
.app-icon {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; display: grid; place-items: center;
}
.app-icon svg { width: 20px; height: 20px; }
.app-tile-name { font-size: 14px; font-weight: 500; }
.app-tile-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ---------- windows (desktop) ---------- */
.window {
  position: absolute; display: flex; flex-direction: column;
  min-width: 320px; min-height: 240px;
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.window.focused { border-color: #3a4356; box-shadow: 0 24px 70px rgba(0,0,0,.65); }
.window.maximized { inset: 0 !important; width: auto !important; height: auto !important; border-radius: 0; }
.window-bar {
  display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 10px;
  background: var(--ink-3); border-bottom: 1px solid var(--line);
  cursor: grab; user-select: none; flex-shrink: 0;
}
.window-bar:active { cursor: grabbing; }
.window-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.window-title { font-size: 12.5px; font-weight: 500; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.window-btns { display: flex; gap: 2px; }
.window-btns button {
  background: none; border: none; color: var(--text-dim);
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
}
.window-btns button:hover { background: var(--accent-soft); color: var(--text); }
.window-btns button.close:hover { background: rgba(224,99,91,.18); color: var(--warn); }
.window-btns svg { width: 13px; height: 13px; }
.window-body { flex: 1; position: relative; background: var(--ink); }
.window-body iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--ink); }
.window-resize {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px;
  cursor: nwse-resize; z-index: 5;
}
.iframe-shield { position: absolute; inset: 0; z-index: 4; display: none; }
body.dragging .iframe-shield { display: block; }

/* ---------- dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 8px; padding: 8px 10px;
  background: rgba(18,21,28,.85); backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 16px;
  z-index: 60;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.dock:empty { display: none; }
.dock-item {
  position: relative; width: 44px; height: 44px;
  border: none; border-radius: 11px; display: grid; place-items: center;
}
.dock-item svg { width: 21px; height: 21px; }
.dock-item::after {
  content: ''; position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
.dock-item.minimized { opacity: .55; }
.dock-item:hover { filter: brightness(1.15); }

/* ---------- Mia chat ---------- */
.mia-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 70;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #1c1405; border: none;
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(232,163,61,.35);
  margin-bottom: env(safe-area-inset-bottom);
}
.mia-fab svg { width: 24px; height: 24px; }
.mia-fab:hover { transform: scale(1.06); }
.mia-panel {
  position: fixed; right: 18px; bottom: 82px; z-index: 70;
  width: min(330px, calc(100vw - 36px));
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
}
.mia-panel header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--ink-3);
  font-weight: 600; font-size: 14px; border-bottom: 1px solid var(--line);
}
.mia-panel header button { background: none; border: none; color: var(--text-dim); font-size: 20px; line-height: 1; padding: 2px 6px; }
.mia-body { padding: 16px; font-size: 13.5px; line-height: 1.55; color: var(--text); }
.mia-body p + p { margin-top: 10px; }
.mia-note { font-size: 11px; color: var(--text-dim); }

/* ---------- mobile (<760px): fullscreen apps, no windows ---------- */
@media (max-width: 759px) {
  .window {
    inset: 0 !important; width: auto !important; height: auto !important;
    min-width: 0; min-height: 0; border-radius: 0; border: none;
  }
  .window-bar { height: 46px; cursor: default; }
  .window-resize { display: none; }
  .window-btns button { width: 38px; height: 38px; }
  .window-btns .min, .window-btns .max { display: none; }
  .window-bar .back { display: grid !important; }
  .menubar-stat { display: none; }
  .home { padding: 24px 18px 130px; }
  .app-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .dock { max-width: calc(100vw - 90px); left: 14px; transform: none; overflow-x: auto; }
}
.window-bar .back {
  display: none; background: none; border: none; color: var(--accent);
  width: 38px; height: 38px; place-items: center; border-radius: 8px;
}
.window-bar .back svg { width: 20px; height: 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- AI app builder ---------- */
.builder-intro { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.builder-label {
  display: block; font-size: 10.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .1em; margin: 10px 0 5px;
}
.mia-body select, .mia-body textarea {
  width: 100%; background: var(--ink-3, #181c24); color: var(--text);
  border: 1px solid var(--line, #262b36); border-radius: 10px;
  padding: 10px 12px; font: inherit; font-size: 13.5px;
}
.mia-body textarea { resize: vertical; min-height: 72px; }
.mia-body select:focus-visible, .mia-body textarea:focus-visible { outline: none; border-color: var(--accent); }
.builder-actions { display: flex; gap: 8px; margin-top: 12px; }
.builder-go {
  flex: 1; background: var(--accent); color: #1c1405; border: none;
  border-radius: 10px; padding: 11px 14px; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; min-height: 44px;
}
.builder-go:hover { filter: brightness(1.08); }
.builder-go:disabled { opacity: .5; cursor: wait; }
.builder-delete {
  background: none; border: 1px solid rgba(224,82,82,.4); color: #e05252;
  border-radius: 10px; padding: 0 14px; font: inherit; font-size: 13px; min-height: 44px; cursor: pointer;
}
.builder-delete:hover { background: rgba(224,82,82,.1); }
.builder-status {
  display: flex; align-items: center; gap: 9px; margin-top: 12px;
  font-size: 12.5px; color: var(--text-dim);
}
.builder-spinner {
  width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: builder-spin .8s linear infinite;
}
@keyframes builder-spin { to { transform: rotate(360deg); } }
.builder-log { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; max-height: 130px; overflow-y: auto; }
.builder-log-item { font-size: 12px; color: var(--text-dim); }
.builder-log-item.ok { color: #6fce8f; }
.builder-log-item.err { color: #e05252; }
@media (max-width: 759px) {
  .mia-panel { bottom: 82px; max-height: calc(100dvh - 120px); overflow-y: auto; }
}

/* live publish row in App Builder */
.builder-live { display:flex; align-items:center; justify-content:space-between; gap:8px; margin:8px 0 2px; padding:8px 10px; background:#181c24; border:1px solid #262b36; border-radius:10px; font-size:12px; }
.builder-live a { color:var(--accent); text-decoration:none; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.builder-live a:not([href]) { color:var(--text-dim, #8a90a0); }
.builder-live button { background:none; border:1px solid #262b36; color:inherit; border-radius:8px; padding:6px 10px; cursor:pointer; font:inherit; font-size:12px; flex-shrink:0; }
.builder-live button:hover { border-color:var(--accent); color:var(--accent); }
