:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #ffffff;
  --badge-dev: #dbeafe;
  --badge-dev-text: #1d4ed8;
  --badge-done: #dcfce7;
  --badge-done-text: #15803d;
  --badge-hold: #fef3c7;
  --badge-hold-text: #b45309;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--sidebar-active);
  font-weight: 600;
}

.sidebar-sub {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: #94a3b8;
}

.project-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.project-item {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.project-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.project-item.active {
  background: rgba(37, 99, 235, 0.25);
  color: var(--sidebar-active);
  font-weight: 500;
}

.main {
  flex: 1;
  padding: 1.5rem 2rem 2.5rem;
  overflow: auto;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.main-header h2 {
  margin: 0.2rem 0 0;
  font-size: 1.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.save-status.dirty { color: #b45309; }
.save-status.saved { color: #15803d; }
.save-status.error { color: #dc2626; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  padding: 0.25rem 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card-header-between {
  justify-content: space-between;
}

.card-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.card-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
}

.detail-toolbar {
  margin-bottom: 1rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem 1.25rem;
  margin-bottom: 0.75rem;
}

.info-item dt {
  margin: 0 0 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.info-item dd {
  margin: 0;
  font-size: 0.92rem;
}

.info-item dd a {
  color: var(--primary);
  text-decoration: none;
}

.info-item dd a:hover {
  text-decoration: underline;
}

.tag-current {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  background: #eff6ff;
  color: #1d4ed8;
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-dev { background: var(--badge-dev); color: var(--badge-dev-text); }
.badge-done { background: var(--badge-done); color: var(--badge-done-text); }
.badge-hold { background: var(--badge-hold); color: var(--badge-hold-text); }
.badge-default { background: #f1f5f9; color: #475569; }

.version-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.version-meta a {
  color: var(--primary);
  text-decoration: none;
}

.version-meta a:hover { text-decoration: underline; }

.version-desc {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  font-size: 0.8rem;
}

.req-table {
  min-width: 1040px;
}

.req-table tbody tr {
  transition: background-color 0.12s ease;
}

.req-table tbody tr:hover {
  background: #f1f5f9;
}

.req-table tbody tr.req-row-mine {
  background: #eff6ff;
}

.req-table tbody tr.req-row-mine:hover {
  background: #dbeafe;
}

.col-idx { width: 48px; }
.col-estimate { width: 130px; }
.col-owner { width: 220px; min-width: 220px; }
.col-status { width: 120px; min-width: 120px; }

.req-table select.status-select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  cursor: pointer;
}

.req-table select.status-select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.estimate-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.estimate-field .estimate-input {
  width: 4.5rem;
  min-width: 0;
  flex: 0 0 4.5rem;
}

.estimate-unit {
  flex-shrink: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.multi-select {
  position: relative;
  width: 100%;
  min-width: 200px;
}

.multi-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.multi-select-trigger:hover {
  border-color: #cbd5e1;
}

.multi-select-trigger:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.multi-select-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select-label.is-placeholder {
  color: var(--muted);
}

.multi-select-arrow {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.multi-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 0.35rem 0;
}

.multi-select-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  text-align: left;
}

.multi-select-item:hover {
  background: #f8fafc;
}

.multi-select-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-width: 14px;
  margin: 0;
  padding: 0;
  border: none;
  flex-shrink: 0;
  cursor: pointer;
}

.multi-select-item span {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  line-height: 1.4;
}

.req-table input.estimate-input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
}

.req-table input.estimate-input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.history-table tbody tr { cursor: pointer; }
.history-table tbody tr:hover { background: #f8fafc; }
.history-table tbody tr.active { background: #eff6ff; }

.empty-hint {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #0f172a 0%, #1e3a5f 100%);
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  text-align: center;
}

.login-sub {
  margin: 0 0 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-field {
  display: block;
  margin-bottom: 1rem;
}

.login-field span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-field input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.login-error {
  min-height: 1.25rem;
  margin: 0 0 0.75rem;
  color: #dc2626;
  font-size: 0.85rem;
}

.login-btn {
  width: 100%;
}

.user-label {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  background: #f1f5f9;
  border-radius: 6px;
}

.plan-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.plan-frame-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.plan-frame {
  display: block;
  width: 100%;
  height: 520px;
  border: none;
  background: #fff;
}

.doc-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.doc-upload-form {
  margin-bottom: 1rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.doc-upload-field {
  display: block;
  margin-bottom: 0.75rem;
}

.doc-upload-field span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.doc-upload-field input[type="text"],
.doc-upload-field input[type="file"] {
  width: 100%;
  max-width: 480px;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.doc-upload-actions {
  display: flex;
  gap: 0.5rem;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.doc-item-main {
  min-width: 0;
  flex: 1;
}

.doc-item-name {
  font-weight: 600;
  margin: 0 0 0.2rem;
}

.doc-item-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.doc-item-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.doc-preview {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.doc-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.doc-preview-body {
  min-height: 420px;
  background: #f1f5f9;
}

.doc-preview-body iframe,
.doc-preview-body img {
  display: block;
  width: 100%;
  min-height: 420px;
  border: none;
  background: #fff;
}

.doc-preview-body img {
  object-fit: contain;
  max-height: 70vh;
}

.doc-preview-fallback {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  .main { padding: 1rem; }
}
