/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #1a2332;
  --sidebar-hover: #243044;
  --sidebar-active: #2d3f5a;
  --sidebar-border: #2a3a50;
  --accent: #4f8ef7;
  --accent-hover: #3a7ae8;
  --accent-light: #e8f0fe;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --purple: #8b5cf6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP",
               "Hiragino Sans", Meiryo, sans-serif;
  font-size: 14px; color: var(--text);
  background: var(--bg); height: 100%; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-logo {
  width: 36px; height: 36px; background: var(--accent);
  border-radius: var(--radius); display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 14px;
  color: #fff; flex-shrink: 0;
}
.brand-name { display: block; color: #fff; font-weight: 600; font-size: 14px; }
.brand-sub  { display: block; color: #8899aa; font-size: 11px; }
.sidebar-nav {
  flex: 1; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: #b0bec8; font-size: 13.5px;
  transition: background .15s, color .15s; text-decoration: none;
}
.sidebar-nav a svg { stroke: currentColor; }
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #e0e8f0; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav a.active svg { stroke: var(--accent); }
.sidebar-footer {
  padding: 12px 8px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.user-avatar {
  width: 32px; height: 32px; background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 13px; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.user-name { color: #e0e8f0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-actions { display: flex; flex-direction: column; gap: 4px; padding: 0 2px; }
.btn-sidebar-action {
  background: none; border: 1px solid var(--sidebar-border);
  color: #8899aa; border-radius: var(--radius);
  padding: 6px 10px; font-size: 12px; cursor: pointer; text-align: left;
  transition: background .15s, color .15s; font-family: inherit;
}
.btn-sidebar-action:hover { background: var(--sidebar-hover); color: #e0e8f0; }
.btn-logout:hover { border-color: var(--danger); color: #f87171; }

/* ── Main content ──────────────────────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
.page-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 16px 28px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 18px; font-weight: 600; color: var(--text); }
.page-actions { display: flex; align-items: center; gap: 10px; }
.page-body { padding: 24px 28px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow);
}
.card-title {
  font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.card + .card { margin-top: 16px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500; cursor: pointer; border: none;
  transition: all .15s; white-space: nowrap; font-family: inherit;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success  { background: var(--success); color: #fff; }
.btn-outline  { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--accent-light); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-yellow { background: #fef9c3; color: #a16207; }

/* ── Form elements ─────────────────────────────────────────────────────────── */
.input, select.input, textarea.input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13.5px; font-family: inherit;
  color: var(--text); background: var(--surface);
  transition: border-color .15s; outline: none;
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,142,247,.12);
}
textarea.input { resize: vertical; min-height: 80px; }
.input-group { display: flex; gap: 8px; align-items: stretch; }
.input-group .input { flex: 1; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.form-row { margin-bottom: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--surface2); padding: 10px 14px; text-align: left;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 14px; font-size: 13.5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.data-table code {
  font-size: 12px; background: var(--surface2); padding: 2px 6px;
  border-radius: 4px; border: 1px solid var(--border); font-family: ui-monospace, monospace;
}

/* ── Status stepper ────────────────────────────────────────────────────────── */
.status-stepper {
  display: flex; align-items: flex-start; gap: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 24px;
}
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.step:not(:last-child)::after {
  content: ""; position: absolute; left: 50%; top: 14px;
  width: 100%; height: 2px; background: var(--border); z-index: 0;
}
.step.done:not(:last-child)::after { background: var(--accent); }
.step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--border); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; z-index: 1;
  border: 2px solid var(--surface2); position: relative;
}
.step.done .step-dot   { background: var(--accent); color: #fff; border-color: var(--accent-light); }
.step.active .step-dot { background: var(--surface); border: 2px solid var(--accent); color: var(--accent); }
.step-label { font-size: 11.5px; color: var(--text-muted); text-align: center; font-weight: 500; max-width: 90px; }
.step.done .step-label   { color: var(--accent); }
.step.active .step-label { color: var(--text); font-weight: 600; }

/* ── Impact analysis ───────────────────────────────────────────────────────── */
.impact-layout { display: grid; grid-template-columns: minmax(420px, 500px) 1fr; gap: 16px; align-items: start; }
.item-list-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-height: 560px; display: flex; flex-direction: column; }
.item-list-search { padding: 10px; border-bottom: 1px solid var(--border); }
.item-list { overflow-y: auto; flex: 1; }
.item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s; font-size: 13px;
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--surface2); }
.item-row.selected { background: var(--accent-light); }
.item-row input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; flex-shrink: 0; }
.item-id  { font-family: monospace; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.item-name-jp { font-size: 12.5px; color: var(--text); }
.item-name-vn { font-size: 11.5px; color: var(--text-muted); }
.impact-summary { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 16px; }
.summary-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.summary-num { font-size: 26px; font-weight: 700; color: var(--accent); line-height: 1; }
.summary-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Review table ──────────────────────────────────────────────────────────── */
.review-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.review-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.review-table th {
  background: var(--surface2); padding: 9px 12px; text-align: left;
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
.review-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13px; }
.review-table tr:last-child td { border-bottom: none; }
.review-table tr:hover td { background: #fafbfc; }
.th-vn { border-left: 3px solid var(--accent); }
.th-jp { border-left: 3px solid var(--purple); }
.td-vn { border-left: 3px solid var(--accent-light); }
.td-jp { border-left: 3px solid #ede9fe; }
.review-check { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.review-check.jp-check { accent-color: var(--purple); }
.review-comment {
  width: 100%; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 12.5px; font-family: inherit;
  resize: vertical; min-height: 52px; color: var(--text);
  margin-top: 4px;
}
.review-comment:focus { outline: none; border-color: var(--accent); }
.review-comment:disabled { background: var(--surface2); color: var(--text-muted); cursor: not-allowed; }
.auto-filled { color: var(--text-muted); font-style: italic; font-size: 11.5px; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: 480px; max-width: 100%;
  box-shadow: var(--shadow-lg); position: relative;
  max-height: 90vh; overflow-y: auto;
}
.modal-lg { width: 640px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 20px; color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 22px; line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ── Upload drop zone ──────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 40px 24px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: var(--accent-light); }
.drop-icon { font-size: 36px; margin-bottom: 10px; }
.file-label { color: var(--accent); cursor: pointer; text-decoration: underline; }
.diff-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.diff-stat { padding: 8px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 600; }
.diff-add    { background: #dcfce7; color: #15803d; }
.diff-remove { background: #fee2e2; color: #b91c1c; }
.diff-change { background: #fef9c3; color: #a16207; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; background: var(--sidebar-bg); display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--surface); border-radius: var(--radius-lg); padding: 40px; width: 380px; max-width: 96vw; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo-icon { width: 44px; height: 44px; background: var(--accent); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; color: #fff; }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); }
.login-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.login-hint { margin-top: 16px; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; color: var(--text-muted); line-height: 1.7; }
.login-lang { position: absolute; top: 20px; right: 24px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; top: 24px; right: 24px; z-index: 9999;
  padding: 12px 18px; border-radius: var(--radius); font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(-8px);
  transition: opacity .25s, transform .25s; max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-info    { background: var(--accent); color: #fff; }
.toast-error   { background: var(--danger); color: #fff; }
.toast-success { background: var(--success); color: #fff; }
.toast-warn    { background: var(--warning); color: #fff; }

/* ── Misc ──────────────────────────────────────────────────────────────────── */
.spinner-sm { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin-right: 6px; vertical-align: middle; }
.loading-row { display: flex; align-items: center; padding: 24px; color: var(--text-muted); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.progress-bar { background: var(--border); border-radius: 999px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: var(--text-muted); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

@media (max-width: 860px) {
  #sidebar { width: 56px; }
  .sidebar-brand .brand-text, .sidebar-nav a span, .sidebar-user .user-info, .sidebar-actions span { display: none; }
  .sidebar-nav a { justify-content: center; }
  .main-content { margin-left: 56px; }
  .impact-layout { grid-template-columns: 1fr; }
  .impact-summary { grid-template-columns: repeat(2,1fr); }
}

/* ── Custom select ─────────────────────────────────────────────────────────── */
select, select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 34px !important;
  cursor: pointer;
}
select:hover, select.input:hover { border-color: var(--accent); }
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,142,247,.12); outline: none; }

/* ── Cursor pointer for interactive elements ───────────────────────────────── */
button, .btn, [role="button"], select { cursor: pointer; }
.node-tog, .it-sarr, .modal-close, .item-row, .drop-zone { cursor: pointer; }
tr[onclick], div[onclick] { cursor: pointer; }
