* { box-sizing: border-box; }
:root { --topbar-height: 56px; }
body { margin: 0; font-family: "Microsoft JhengHei", "Segoe UI", sans-serif; background: #f5f5f5; color: #222; overflow-x: hidden; }
a { color: #1976d2; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { background: #263238; border-bottom: 1px solid #1f2937; position: sticky; top: 0; z-index: 1000; }
.topbar-inner { display: flex; align-items: center; gap: 0.75rem; min-height: var(--topbar-height); padding: 0.5rem 1rem; }
.brand a { color: #fff; font-weight: 700; }
.nav-toggle { display: none; }

.app-shell { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 260px; background: #1f2937; color: #fff; padding: 0.85rem; border-right: 1px solid #111827; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.5rem; }
.menu-group { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); border-radius: 6px; padding: 0.2rem 0.4rem 0.4rem 0.4rem; }
.menu-group summary { cursor: pointer; list-style: none; color: #e5e7eb; font-weight: 700; padding: 0.35rem 0.2rem; }
.menu-group summary::-webkit-details-marker { display: none; }
.menu-group summary::before { content: "▸ "; color: #9ca3af; }
.menu-group[open] summary::before { content: "▾ "; }
.menu-group a { display: block; color: #d1d5db; padding: 0.3rem 0.5rem 0.3rem 1rem; border-radius: 4px; margin-bottom: 0.15rem; }
.menu-group a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.menu-group a.active { background: #0ea5e9; color: #fff; font-weight: 700; }
.menu-group.active-group summary { color: #fff; }

.content { flex: 1; min-width: 0; padding: 1rem; }

.pageTitle { font-size: 1.5rem; margin: 0 0 1rem 0; color: #333; }
.card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 1rem; margin-bottom: 1rem; }

table { width: 100%; border-collapse: collapse; background: #fff; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
th, td { border: 1px solid #ddd; padding: 0.5rem 0.75rem; text-align: left; vertical-align: top; }
th { background: #37474f; color: #fff; }
tr:nth-child(even) { background: #fafafa; }

.btn { display: inline-block; padding: 0.4rem 0.8rem; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem; }
.btn-primary { background: #1976d2; color: #fff; }
.btn-secondary { background: #757575; color: #fff; }
.btn-danger { background: #c62828; color: #fff; }
.btn-small { padding: 0.25rem 0.5rem; font-size: 0.85rem; }
.btn + .btn { margin-left: 0.5rem; }

input, select, textarea { padding: 0.4rem; border: 1px solid #ccc; border-radius: 4px; }
.form-row { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end; }
.form-field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 180px; }
.form-field label { font-weight: 600; font-size: 0.9rem; }
.form-actions { margin-top: 0.75rem; }

.alert { padding: 0.6rem 0.8rem; border-radius: 6px; margin: 0 0 1rem 0; }
.alert-success { background: #e8f5e9; border: 1px solid #a5d6a7; }
.alert-error { background: #ffebee; border: 1px solid #ef9a9a; }

.muted { color: #666; }

/* 報價明細階層：產品列與其下加工方式列 */
.detail-group-header { background: #e3f2fd !important; font-weight: 600; }
.detail-group-line { background: #fff !important; }
.detail-group-line td:nth-child(5) { padding-left: 1.5rem; }
.detail-toggle { width: 24px; height: 24px; padding: 0; line-height: 1; font-size: 1.1rem; cursor: pointer; border: 1px solid #ccc; border-radius: 3px; background: #fff; }
.detail-toggle:hover { background: #f0f0f0; }

/* DXF 線上檢視：SVG 嵌在 iframe 內 */
.dxf-svg-container { width: 100%; min-height: 500px; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; background: #fafafa; }
.dxf-svg-iframe { width: 100%; height: 70vh; min-height: 480px; border: none; }

@media (max-width: 1200px) {
  .content { padding: 0.9rem; }
  .card { padding: 0.9rem; }
}

@media (max-width: 960px) {
  .nav-toggle { display: inline-block; }
  .sidebar { position: fixed; top: var(--topbar-height); left: 0; bottom: 0; width: min(86vw, 320px); transform: translateX(-100%); transition: transform 0.2s ease; z-index: 1100; overflow-y: auto; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 0.8rem; width: 100%; }
  .btn { width: auto; }
  .btn + .btn { margin-left: 0.35rem; }
  .form-row { gap: 0.6rem; }
  .form-field { min-width: 150px; }
  .dxf-svg-container { min-height: 380px; }
  .dxf-svg-iframe { min-height: 360px; height: 62vh; }
}

@media (max-width: 768px) {
  .topbar-inner { padding: 0.45rem 0.75rem; }
  .brand a { font-size: 0.95rem; }
  .pageTitle { font-size: 1.25rem; }
  .content { padding: 0.7rem; }
  .card { border-radius: 6px; padding: 0.75rem; }
  th, td { padding: 0.45rem 0.55rem; font-size: 0.92rem; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-field { min-width: 0; width: 100%; }
  input, select, textarea { width: 100%; max-width: 100%; }
  .form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .form-actions .btn { margin-left: 0 !important; }
  .detail-group-line td:nth-child(5) { padding-left: 0.85rem; }
  .dxf-svg-container { min-height: 320px; }
  .dxf-svg-iframe { min-height: 300px; height: 56vh; }
}

@media (max-width: 480px) {
  .topbar-inner { gap: 0.5rem; padding: 0.4rem 0.6rem; }
  .brand a { font-size: 0.9rem; }
  .content { padding: 0.55rem; }
  .card { padding: 0.65rem; }
  .btn { width: 100%; }
  .btn + .btn { margin-left: 0; margin-top: 0.4rem; }
  .detail-toggle { width: 22px; height: 22px; font-size: 1rem; }
  .dxf-svg-container { min-height: 280px; }
  .dxf-svg-iframe { min-height: 260px; height: 52vh; }
}
