:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1917;
  --ink-2: #57534e;
  --muted: #78716c;
  --line: #e7e3dc;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f1;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --err: #b91c1c;
  --err-soft: #fdecec;
  --code-bg: #1c1917;
  --code-ink: #e7e5e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28,25,23,.05), 0 6px 24px rgba(28,25,23,.06);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --surface: #1c1a17;
    --surface-2: #232120;
    --ink: #f5f5f4;
    --ink-2: #d6d3d1;
    --muted: #a8a29e;
    --line: #34312d;
    --accent: #2dd4bf;
    --accent-ink: #042f2e;
    --accent-soft: #123532;
    --ok: #4ade80; --ok-soft: #12301d;
    --warn: #fbbf24; --warn-soft: #33270e;
    --err: #f87171; --err-soft: #3a1616;
    --code-bg: #0c0b0a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; line-height: 1.3; margin: 0 0 6px; font-weight: 700; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 16px; margin: 8px 0 4px; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 12px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(16px, calc((100vw - 1240px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 20px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--ink-2); padding: 6px 12px; border-radius: 10px; font-weight: 500; }
.topbar nav a:hover { background: var(--surface); text-decoration: none; }
.topbar nav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 80px; }

/* ---------- cards & forms ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card-title { margin-bottom: 14px; font-size: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; color: var(--ink-2); }
input, textarea, select {
  font: inherit; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type=color] { padding: 4px; height: 44px; }
input[type=file] { padding: 8px; }
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid2.tight { gap: 10px; margin-bottom: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 14px/1 var(--font);
  padding: 11px 16px; min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: transform .06s, background .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.notice { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; border: 1px solid transparent; line-height: 1.8; }
.notice.info { background: var(--accent-soft); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--err-soft); color: var(--err); }
.err-text { color: var(--err); margin-top: 6px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.pill.wait { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------- auth ---------- */
.auth { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center; }
.auth-card form { text-align: right; margin-top: 18px; }
.auth-mark { font-size: 36px; color: var(--accent); }

/* ---------- dashboard ---------- */
.hero { padding: 12px 0 18px; }
.hero h1 { font-size: 30px; }
.tabs { display: flex; gap: 6px; margin: -6px -6px 18px; padding-bottom: 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { font: 600 14px var(--font); padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tab:hover { background: var(--surface-2); }
.tab.on { background: var(--accent-soft); color: var(--accent); }
.tabpane { display: none; }
.tabpane.on { display: block; }
.tabpane > label { margin-bottom: 14px; }

.working { display: flex; align-items: center; gap: 14px; padding: 16px; margin-top: 16px; border-radius: 12px; background: var(--accent-soft); }
.small-working { margin-top: 12px; padding: 12px; }
.spinner { width: 26px; height: 26px; flex: none; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section-title { margin: 28px 0 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.pcard { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.pcard:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.pcard-top { display: flex; justify-content: space-between; align-items: center; }
.picon { font-size: 24px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0 0 10px; min-height: 2.6em; }
.pcard-foot { margin-top: auto; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

/* ---------- project ---------- */
.proj-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.proj-head h1 { margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.proj-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.col-side { position: sticky; top: 76px; }

.files-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg-btn { font: 600 13px var(--font); border: 0; background: transparent; color: var(--ink-2); padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.seg-btn.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.view { display: none; }
.view.on { display: block; }

.explorer { display: grid; grid-template-columns: 230px minmax(0, 1fr); height: 620px; }
.file-list { list-style: none; margin: 0; padding: 6px; overflow: auto; border-left: 1px solid var(--line); background: var(--surface-2); }
.file-list button { width: 100%; display: flex; justify-content: space-between; gap: 6px; text-align: left; direction: ltr; font: 13px var(--mono); padding: 7px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.file-list button:hover { background: var(--surface); }
.file-list button.on { background: var(--accent-soft); color: var(--accent); }
.file-list button.bin { opacity: .65; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsize { color: var(--muted); font-size: 11px; flex: none; }
.editor { display: flex; flex-direction: column; min-width: 0; }
.editor-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.editor-bar code { background: none; border: 0; direction: ltr; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-actions { display: flex; gap: 6px; }
#code {
  flex: 1; border: 0; border-radius: 0; resize: none; min-height: 0;
  background: var(--code-bg); color: var(--code-ink);
  font: 13px/1.6 var(--mono); padding: 14px; tab-size: 4; white-space: pre;
}
#code:focus { box-shadow: none; }

.view-preview { padding: 20px; background: var(--surface-2); }
.phone { width: 380px; max-width: 100%; height: 720px; margin: 0 auto 12px; border: 10px solid var(--ink); border-radius: 38px; overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.phone iframe { width: 100%; height: 100%; border: 0; display: block; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.history li { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.history li:last-child { border: 0; padding-bottom: 0; }
.quote { margin-top: 6px; padding: 8px 12px; border-right: 3px solid var(--line); color: var(--ink-2); background: var(--surface-2); border-radius: 6px; }
.notes { margin-top: 8px; white-space: pre-wrap; }

.builds { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.build { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.settings-grid > section:first-of-type { grid-row: span 2; }
.provider { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.provider:last-of-type { border-bottom: 0; margin-bottom: 8px; }
.settings-grid .card label { margin-bottom: 10px; }
.repo-status { display: flex; gap: 10px; align-items: center; margin: 4px 0 12px; flex-wrap: wrap; }
.save-bar { grid-column: 1 / -1; position: sticky; bottom: 16px; display: flex; justify-content: flex-start; }
.save-bar .btn { box-shadow: 0 8px 24px rgba(15,118,110,.3); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 500; max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0; visibility: hidden; pointer-events: none; transition: transform .25s, opacity .25s, visibility .25s; z-index: 50; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.toast.err { background: var(--err); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .proj-grid { grid-template-columns: 1fr; }
  .col-side { position: static; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid > section:first-of-type { grid-row: auto; }
}
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .explorer { grid-template-columns: 1fr; grid-template-rows: 180px 460px; height: auto; }
  .file-list { border-left: 0; border-bottom: 1px solid var(--line); }
  .topbar { padding: 10px 12px; }
  .brand span:last-child { display: none; }
  .hero h1 { font-size: 24px; }
  .phone { height: 600px; border-width: 6px; border-radius: 24px; }
}
