/* ============================================================
 * Tonerico UI styles  (M1-0 mock)
 * デザインシステム: docs/UI_DESIGN_SYSTEM.md
 * ========================================================== */

/* ---------- CSS variables ---------- */
:root {
  /* 背景 */
  --bg-base:        #0f172a;
  --bg-card:        #1e293b;
  --bg-elevated:    #334155;
  --bg-terminal:    #000000;
  --bg-input:       #0b1220;

  /* ボーダー */
  --border:         #1e293b;
  --border-strong:  #334155;
  --border-focus:   #3b82f6;

  /* テキスト */
  --text:           #e2e8f0;
  --text-dim:       #94a3b8;
  --text-muted:     #64748b;
  --text-inverse:   #0f172a;

  /* アクセント */
  --accent:         #3b82f6;
  --accent-hover:   #2563eb;

  /* 状態 */
  --success:        #10b981;
  --warning:        #f59e0b;
  --error:          #ef4444;
  --offline:        #64748b;

  /* フォント */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'Fira Code', 'Consolas', 'Monaco', 'Menlo', monospace;

  --fs-xs:   11px;
  --fs-sm:   12px;
  --fs-md:   14px;
  --fs-lg:   16px;
  --fs-xl:   20px;
  --fs-xxl:  24px;

  --lh-tight: 1.3;
  --lh-base:  1.5;
  --lh-loose: 1.7;

  /* スペーシング */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;

  /* レイアウト */
  --sidebar-width: 280px;
  --terminal-height: 240px;
}

/* ---------- reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: var(--lh-base);
  background: var(--bg-base);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

button { font-family: inherit; }

/* a11y helper */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- ログインオーバーレイ ---------- */
.login-overlay {
  display: flex; justify-content: center; align-items: center;
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg-base); z-index: 100;
}
.login-box {
  text-align: center; width: 100%; max-width: 320px;
  padding: var(--sp-8);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}
.login-box h1 { font-size: var(--fs-xl); margin-bottom: var(--sp-2); }
.login-box p { color: var(--text-dim); margin-bottom: var(--sp-4); }
.login-box form { display: flex; flex-direction: column; gap: var(--sp-3); }
.login-error { color: var(--error); font-size: var(--fs-sm); min-height: 1.2em; margin-top: var(--sp-2); }

/* ---------- 2カラム骨格 ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
  width: 100%;
}

/* ---------- サイドバー ---------- */
.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  padding: var(--sp-4);
  gap: var(--sp-4);
  overflow-y: auto;
}

.sidebar-header { display: flex; flex-direction: column; gap: var(--sp-2); }
.brand {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-bar { display: flex; align-items: center; gap: var(--sp-2); }

/* Adapter card / Storage card / Downloads card (サイドバー共通の形) */
.adapter-card,
.storage-card,
.downloads-card {
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: var(--sp-3);
}
.card-mini-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
}
.adapter-card-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}
.adapter-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.adapter-row { display: flex; justify-content: space-between; align-items: center; font-size: var(--fs-xs); }
.adapter-row dt { color: var(--text-dim); }
.adapter-row dd { margin: 0; }

/* Storage card */
.storage-meta { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-2); }
.storage-row { display: flex; justify-content: space-between; font-size: var(--fs-xs); }
.storage-row dt { color: var(--text-dim); }
.storage-row dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.storage-files {
  list-style: none;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-tight);
  max-height: 140px;
  overflow-y: auto;
  padding: var(--sp-2);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.storage-files li { word-break: break-all; padding: 1px 0; }
.storage-files li.gguf { color: var(--success); font-weight: 600; }

/* Downloads card */
.downloads-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.download-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: var(--fs-xs);
}
.download-item .dl-name { font-family: var(--font-mono); color: var(--text); word-break: break-all; }
.download-item .dl-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}
.download-item .dl-bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }
.download-item .dl-meta { display: flex; justify-content: space-between; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.text-dim { color: var(--text-dim); }
.text-dim.small { font-size: var(--fs-xs); }

.badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 2px var(--sp-2);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
}
.badge-active { background: color-mix(in srgb, var(--success) 20%, transparent); color: var(--success); }

/* Sidebar nav */
.sidebar-nav { display: flex; flex-direction: column; gap: var(--sp-1); }
.nav-item {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-dim);
  border-radius: 4px;
  font-size: var(--fs-sm);
}
.nav-item:hover { background: var(--bg-elevated); color: var(--text); text-decoration: none; }

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
}

/* ---------- メインカラム ---------- */
.main {
  display: grid;
  grid-template-rows: auto auto auto 1fr var(--terminal-height);
  min-width: 0;
  min-height: 0;
}

.main-header {
  display: flex;
  align-items: end;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
}
.header-field { flex: 1; display: flex; flex-direction: column; gap: var(--sp-1); }
.header-field label { font-size: var(--fs-xs); color: var(--text-dim); }
.header-actions { display: flex; gap: var(--sp-2); }

/* Info card (状態サマリ) */
.info-card {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-3) var(--sp-6);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
}
.info-row { display: contents; }
.info-row code { color: var(--text); }

/* ---------- タブ ---------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab:hover:not([aria-disabled="true"]) { color: var(--text); }
.tab:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; border-radius: 2px; }
.tab-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab[aria-disabled="true"] { color: var(--text-muted); cursor: not-allowed; }

/* ---------- Workspace ---------- */
.workspace {
  padding: var(--sp-4) var(--sp-6);
  overflow-y: auto;
  min-height: 0;
}
.workspace:focus { outline: none; }
.tab-panel { display: block; }
.tab-panel[hidden] { display: none; }

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  margin-bottom: var(--sp-4);
}
.card-header { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.card-header h2 { font-size: var(--fs-md); font-weight: 600; }
.card-body { padding: var(--sp-4); }
.card-body p { margin-bottom: var(--sp-2); }
.card-body p:last-child { margin-bottom: 0; }

.endpoint-hints { list-style: none; margin-top: var(--sp-2); }
.endpoint-hints li { padding: var(--sp-1) 0; }
.endpoint-hints code { color: var(--accent); }

/* ---------- 入力 ---------- */
.input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--border-focus); }
.input.input-mono { font-family: var(--font-mono); font-size: var(--fs-xs); line-height: var(--lh-base); }
.input-mono { font-family: var(--font-mono); font-size: var(--fs-xs); line-height: var(--lh-base); }
select.input { appearance: none; padding-right: var(--sp-6); }

/* ---------- Form (Tasks / Config) ---------- */
.form-grid { display: flex; flex-direction: column; gap: var(--sp-3); }
.form-field { display: flex; flex-direction: column; gap: var(--sp-1); }
.form-field > span { font-size: var(--fs-xs); color: var(--text-dim); }
.form-actions { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.form-status { font-size: var(--fs-xs); font-weight: 600; }
.form-status.success { color: var(--success); }
.form-status.error   { color: var(--error); }
.form-status.pending { color: var(--warning); }

/* ---------- Tasks タブ ---------- */
.sub-h {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: var(--sp-4) 0 var(--sp-2);
}
.task-current {
  padding: var(--sp-3);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: var(--sp-2);
}
.task-current .tc-row { display: flex; justify-content: space-between; font-size: var(--fs-xs); }
.task-current .tc-name { font-family: var(--font-mono); color: var(--text); }
.task-current .tc-state { color: var(--text-dim); }
.task-current .tc-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--sp-2);
}
.task-current .tc-bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }
.task-log {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-tight);
  color: var(--text);
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: var(--sp-3);
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

/* ---------- Config タブ ---------- */
.config-errors {
  list-style: none;
  margin-top: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: color-mix(in srgb, var(--error) 10%, transparent);
  border: 1px solid var(--error);
  border-radius: 4px;
  color: var(--error);
  font-size: var(--fs-xs);
}
.config-errors li { padding: 2px 0; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { height: 24px; padding: 0 var(--sp-2); font-size: var(--fs-xs); }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--bg-elevated); color: var(--text-muted); }

.btn-danger { background: var(--error); color: white; }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--error) 80%, black); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-strong);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); background: var(--bg-elevated); }

/* ---------- ステータスドット ---------- */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--offline);
}
.dot-online   { background: var(--success); }
.dot-starting { background: var(--warning); animation: pulse 1s infinite; }
.dot-error    { background: var(--error); }
.dot-offline  { background: var(--offline); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- ターミナル ---------- */
.terminal {
  display: flex;
  flex-direction: column;
  background: var(--bg-terminal);
  border-top: 1px solid var(--border-strong);
  min-height: 0;
}
.terminal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-strong);
}
.terminal-title { font-size: var(--fs-xs); font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.terminal-body {
  flex: 1;
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-tight);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 0;
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border-strong);
    flex-direction: row;
    overflow-x: auto;
    align-items: center;
  }
  .sidebar-header, .adapter-card, .sidebar-nav, .sidebar-footer { flex-shrink: 0; }
  .main { grid-template-rows: auto auto auto 1fr 160px; }
  .main-header { flex-wrap: wrap; }
  .info-card { grid-template-columns: 1fr; }
}
