:root {
  --bg: #eef3f8;
  --sidebar: #0f1f33;
  --sidebar-soft: #182b45;
  --text: #142033;
  --muted: #6b778c;
  --card: #ffffff;
  --line: #e1e8f0;
  --primary: #1e66f5;
  --primary-dark: #154fc2;
  --danger: #d92d20;
  --success: #20b26b;
  --warning: #f5a524;
  --shadow: 0 18px 45px rgba(30, 53, 86, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, var(--sidebar), #0a1728); color: #fff; padding: 24px 18px; }
.brand { display: flex; align-items: center; gap: 14px; padding: 8px 8px 28px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; background: var(--primary); font-weight: 800; }
.brand-title, .brand-subtitle { margin: 0; }
.brand-title { font-size: 20px; font-weight: 800; }
.brand-subtitle { color: #9fb2ce; font-size: 13px; }
.menu { display: grid; gap: 8px; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; border-radius: 14px; padding: 14px 16px; background: transparent; color: #bfd0e8; cursor: pointer; font: inherit; font-weight: 700; text-align: left; }
.menu-item.active, .menu-item:hover { background: var(--sidebar-soft); color: #fff; }
.menu-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); }
.workspace { padding: 32px; overflow: auto; }
.workspace-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--primary); font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
h1, h2 { margin: 0; }
h1 { font-size: 34px; }
.server-status { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); padding: 10px 14px; color: var(--muted); box-shadow: var(--shadow); }
.status-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--warning); }
.status-dot.online { background: var(--success); }
.panel, .tabs-shell { border: 1px solid var(--line); border-radius: 24px; background: var(--card); box-shadow: var(--shadow); }
.panel { padding: 24px; }
.panel-header { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 18px; }
.panel-header p { margin: 8px 0 0; color: var(--muted); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.primary-action, .secondary-action { border: 0; border-radius: 14px; cursor: pointer; font-weight: 800; padding: 12px 18px; }
.primary-action { background: var(--primary); color: #fff; }
.primary-action:hover { background: var(--primary-dark); }
.secondary-action { background: #e8eef7; color: var(--text); }
.secondary-action.small { border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.secondary-action.danger { color: var(--danger); }
.file-table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 18px; }
.ai-data-panel { margin-top: 22px; }
.ai-data-status { display: inline-flex; align-items: center; min-height: 36px; border-radius: 999px; background: #eef7ff; color: var(--primary-dark); padding: 8px 12px; font-weight: 800; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 16px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #f7f9fc; color: var(--muted); font-size: 13px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.file-row { cursor: default; }
.file-row:hover, .file-row.selected { background: #f2f7ff; }
.file-name { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.file-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: #eaf1ff; color: var(--primary); }
.tabs-shell { margin-top: 22px; overflow: hidden; }
.tab-strip { display: flex; gap: 4px; min-height: 48px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; background: #f7f9fc; padding: 10px 14px; cursor: pointer; font-weight: 800; white-space: nowrap; }
.tab.active { background: #fff; color: var(--primary); }
.tab .close { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; }
.editor-shell { padding: 18px; }
.editor-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.formula-bar { display: grid; grid-template-columns: 90px 1fr; gap: 10px; margin-bottom: 12px; }
.cell-address, .formula-input { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font: inherit; }
.cell-address { background: #f7f9fc; font-weight: 800; color: var(--muted); }
.formula-input { width: 100%; }
.sheet-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; max-height: 68vh; }
.sheet { border-collapse: separate; border-spacing: 0; min-width: 1100px; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
.sheet th { position: sticky; top: 0; z-index: 1; height: 32px; min-width: 96px; background: #f3f6fb; text-align: center; color: var(--muted); }
.sheet .corner, .sheet .row-head { position: sticky; left: 0; z-index: 2; min-width: 48px; width: 48px; background: #f3f6fb; text-align: center; color: var(--muted); font-weight: 800; }
.sheet .corner { top: 0; z-index: 3; }
.sheet input { width: 100%; min-width: 96px; height: 34px; border: 0; padding: 6px 8px; font: inherit; background: #fff; }
.sheet input:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
.context-menu { position: fixed; z-index: 20; width: 170px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); padding: 6px; }
.context-menu button { display: block; width: 100%; border: 0; border-radius: 10px; background: transparent; cursor: pointer; padding: 10px 12px; text-align: left; font: inherit; }
.context-menu button:hover { background: #f2f7ff; }
.context-menu .danger { color: var(--danger); }
.muted { color: var(--muted); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(10, 23, 40, 0.52); padding: 24px; }
.modal[hidden] { display: none; }
.modal-card { width: min(980px, 96vw); max-height: 86vh; overflow: auto; border: 1px solid var(--line); border-radius: 24px; background: var(--card); box-shadow: var(--shadow); padding: 24px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 2; }
  .workspace-header, .panel-header { align-items: flex-start; flex-direction: column; }
}
.page-section[hidden] { display: none; }
.ai-grid { display: grid; grid-template-columns: repeat(2, minmax(240px, 1fr)); gap: 16px; }
.ai-grid label { display: grid; gap: 8px; color: var(--muted); font-weight: 800; }
.ai-grid input, .ai-grid select, .ai-prompt { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font: inherit; color: var(--text); background: #fff; }
.ai-status { margin-top: 16px; border-radius: 14px; background: #f2f7ff; color: var(--primary-dark); padding: 12px 14px; font-weight: 700; }
.ai-status.error { background: #fff1f0; color: var(--danger); }
.ai-chat-panel { margin-top: 22px; }
.ai-prompt { min-height: 130px; resize: vertical; }
.chart-card { margin-top: 14px; border: 1px solid var(--line); border-radius: 18px; background: #fff; padding: 16px; overflow: auto; }
.chart-card h3 { margin: 0 0 12px; }
.chart-card canvas { width: 100%; max-width: 100%; height: auto; }
.ai-response { min-height: 180px; margin: 14px 0 0; border: 1px solid var(--line); border-radius: 16px; background: #0f1f33; color: #d9e7ff; padding: 16px; white-space: pre-wrap; overflow: auto; }
@media (max-width: 900px) { .ai-grid { grid-template-columns: 1fr; } }
.brand-logo { display: block; width: 100%; max-width: 240px; border-radius: 14px; box-shadow: 0 10px 28px rgba(0,0,0,0.22); }
.brand { justify-content: center; padding-bottom: 24px; }
