/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; background: #f9f9f9; overflow-x: hidden; }

/* ===== Top Header Bar ===== */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1e3a8a;
    color: #fff;
    padding: 0 20px;
    height: 54px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
}

.site-header .page-title {
    font-size: 17px;
    font-weight: bold;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quick-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.quick-links a {
    color: #dbeafe;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 10px;
    border-radius: 999px;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.quick-links a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.quick-links a.active { background: rgba(255,255,255,0.18); color: #fff; }

/* ===== Header Right & User Info (修復按鈕跌落下一行) ===== */
.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
    flex-shrink: 0;
}

.site-header .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    white-space: nowrap;
}
.site-header .user-info span { font-weight: bold; }

/* ===== Hamburger Button ===== */
.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-radius: 4px;
    transition: background 0.2s;
    flex-shrink: 0; /* 防止按鈕被壓縮 */
}
.hamburger-btn:hover { background: rgba(255,255,255,0.15); }
.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.3s;
}
/* 漢堡按鈕 X 動畫 */
.hamburger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.hamburger-wrapper {
    position: relative;
    display: inline-block;
}
.hamburger-badge {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: #dc3545; /* Bootstrap bg-danger 顏色 */
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    /* 如果你用 Bootstrap 可以唔使呢幾行，直接用 class="badge bg-danger rounded-pill position-absolute" */
}
/* Badge 基礎樣式 */
.badge {
    display: inline-block;
    padding: 0.25em 0.6em;
    font-size: 0.75em;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
    margin-left: 5px; /* 與文字保持少少距離 */
}

/* 紅色背景 */
.bg-danger {
    background-color: #dc3545 !important;
}

/* 膠囊形狀 (全圓角) */
.rounded-pill {
    border-radius: 50rem !important;
}

/* ===== Slide-in Side Menu ===== */
.side-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1100;
}
.side-menu-overlay.open { display: block; }

.side-menu {
    position: fixed;
    top: 0; right: -400px;
    min-width: 280px;
    max-width: 85vw; /* 防止喺超細螢幕被斬開 */
    height: 100dvh;
    background: #1e293b;
    color: #e2e8f0;
    z-index: 1200;
    transition: right 0.2s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: -2px 0 8px rgba(0,0,0,0.2);
}
.side-menu.open { right: 0; }

.side-menu-header {
    padding: 18px 20px;
    background: #0f172a;
    border-bottom: 1px solid #334155;
}
.side-menu-header .user-name { font-size: 16px; font-weight: bold; color: #fff; word-break: break-all; }
.side-menu-header .user-email { font-size: 12px; color: #94a3b8; margin-top: 3px; word-break: break-all; }
.side-menu-header .user-subscription-expiry{
    margin-top: 6px;
    font-size: 13px;
    color: #64748b;
}
.side-menu-header .user-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    background: #3b82f6;
    color: #fff;
}
.side-menu-header .user-badge.admin { background: #dc2626; }

.side-menu nav { flex: 1; padding: 10px 0; }
.side-menu nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 22px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    white-space: normal; /* 允許文字太長時自動換行，防止斬字 */
    line-height: 1.4;
}
.side-menu nav a:hover { background: #334155; color: #fff; }
.side-menu nav a.active {
    background: #1e3a8a;
    color: #fff;
    border-left-color: #60a5fa;
}
.side-menu nav a .icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.side-menu nav .menu-section {
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1.2px;
    color: #64748b;
    padding: 14px 22px 4px;
    text-transform: uppercase;
}
.side-menu nav hr { border: none; border-top: 1px solid #334155; margin: 6px 0; }

.side-menu-footer {
    padding: 14px 22px;
    border-top: 1px solid #334155;
}
.side-menu-footer a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f87171;
    font-size: 14px;
    text-decoration: none;
}
.side-menu-footer a:hover { color: #fca5a5; }

/* ===== Page Content Wrapper ===== */
.page-content { padding: 10px; }
.container { display: flex; gap: 10px; flex-wrap: wrap; }
.form-section { flex: 1; min-width: 320px; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);}
.result-section { flex: 2; min-width: 500px; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); height: calc(100dvh - 74px); overflow-y: auto; }
.input-group { margin-bottom: 12px; display: flex; align-items: center; }
.input-group label { width: 150px; font-weight: bold; font-size: 14px; flex-shrink: 0; }
.input-group input, .input-group select { padding: 6px; border: 1px solid #ccc; border-radius: 4px; width: 100%; }
.currency-toggle { margin-bottom: 15px; padding: 12px; background: #e2e8f0; border-radius: 5px; font-weight: bold; }

/* ===== Table Styles ===== */
#table-container { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; white-space: nowrap; }
th, td { border: 1px solid #cbd5e1; padding: 8px; text-align: right; }
th { background: #1e3a8a; color: white; text-align: center; }
td:nth-child(1), td:nth-child(2) { text-align: center; }
tr:nth-child(even) { background-color: #f8fafc; }
tr:hover { background-color: #e2e8f0; }

/* ===== Responsive Adjustments (修復窄螢幕問題) ===== */
@media (max-width: 860px) {
    .container { flex-direction: column; }
    .form-section, .result-section { min-width: 100%; width: 100%; flex: none; }
}

@media (max-width: 640px) {
    .site-header { padding: 0 12px; }
    .header-left { gap: 10px; min-width: 0; }
    .site-header .page-title { font-size: 15px; max-width: 52vw; }
    .quick-links { display: none; }
}

@media (max-width: 480px) {
    .hamburger-btn { padding: 4px; }
    .hamburger-btn span { width: 22px; }
    .input-group { flex-direction: column; align-items: flex-start; gap: 5px; }
    .input-group label { width: auto; }
}
/* ===== v2 新增 ===== */
[hidden] { display: none !important; }
.table-scroll { overflow-x: auto; }
.side-menu-footer .side-menu-logout {
    font: inherit; background: none; border: 0; padding: 0; width: 100%; cursor: pointer; text-align: left;
    display: flex; align-items: center; gap: 10px; color: #f87171; font-size: 14px;
}
.side-menu-footer .side-menu-logout:hover { color: #fca5a5; }
.debug-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
    background: #1a1a2e; color: #e0e0e0; font: 12px/1.6 monospace;
    padding: 6px 16px; display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
    border-top: 2px solid #008851;
}
.debug-bar .toggle { margin-left: auto; color: #a78bfa; text-decoration: none; }
.debug-log {
    display: none; position: fixed; bottom: 32px; left: 0; right: 0; z-index: 9998;
    max-height: 300px; overflow-y: auto; background: #0f0f23; color: #cdd6f4;
    font: 11px/1.8 monospace; padding: 10px 16px; border-top: 1px solid #333;
}
.debug-log.open { display: block; }
.debug-log > div { border-bottom: 1px solid #222; padding: 4px 0; }
.debug-bar .ok { color: #4ade80; } .debug-bar .warn, .debug-log .warn { color: #facc15; }
.debug-bar .info { color: #60a5fa; } .debug-bar .muted, .debug-log .muted { color: #888; }
.debug-log .sql { color: #89dceb; margin-left: 8px; }

/* ----- 表單 / 提示 / 按鈕（取代舊版 inline style）----- */
.container.narrow { max-width: 600px; margin: 0 auto; display: block; }
.container.narrow .form-section { width: 100%; }
.section-title { margin-bottom: 15px; border-bottom: 2px solid #1e3a8a; padding-bottom: 10px; }
.alert { padding: 10px 12px; border-radius: 4px; margin-bottom: 15px; border: 1px solid transparent; }
.alert-error { background: #fee2e2; color: #b91c1c; border-color: #f87171; }
.alert-success { background: #dcfce7; color: #166534; border-color: #86efac; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.input-group.stacked { flex-direction: column; align-items: flex-start; margin-bottom: 15px; }
.input-group.stacked label { width: 100%; margin-bottom: 5px; }
.input-group.stacked input { width: 100%; padding: 10px; box-sizing: border-box; }
.terms-box { background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 6px; padding: 14px; margin-bottom: 10px; }
.terms-title { font-weight: bold; text-align: center; }
.terms-body { overflow: auto; font-size: 14px; line-height: 1.7; color: #334155; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; cursor: pointer; }
.checkbox-row input { margin-top: 4px; }
.info-box { background: #f8fafc; padding: 15px; border-radius: 6px; border: 1px solid #e2e8f0; margin-bottom: 20px; line-height: 1.8; }
.hint { font-size: 0.9em; color: #666; margin-top: 10px; }

.btn { display: inline-block; padding: 10px 12px; border: 0; border-radius: 4px; color: #fff; font-weight: bold;
       font-size: 15px; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn-block { width: 100%; padding: 12px; font-size: 16px; margin-top: 10px; }
.btn-primary { background: #1e3a8a; }
.btn-blue { background: #3b82f6; }
.btn-danger { background: #ef4444; }
.btn-success { background: #10b981; }
.btn-grey { background: #64748b; }
.btn-row { display: flex; gap: 10px; margin-top: 20px; }
.btn-row > * { flex: 1; }
.btn-row > form > .btn { width: 100%; }
.btn-row > .grow-2 { flex: 2; }

/* ----- 首頁 ----- */
.dashboard { max-width: 1000px; margin: 0 auto; padding: 20px; }
.welcome-card { background: #fff; border-radius: 8px; padding: 20px; margin-bottom: 30px; box-shadow: 0 2px 4px rgba(0,0,0,.05); border-left: 5px solid #1e3a8a; }
.welcome-card h2 { margin-top: 0; color: #1e3a8a; }
.welcome-meta { color: #475569; font-size: 15px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-muted { color: #64748b; } .status-danger { color: #ef4444; } .status-warning { color: #f59e0b; } .status-success { color: #10b981; }
.pill { padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: bold; }
.pill-admin { background: #fee2e2; color: #b91c1c; }
.dashboard-heading { color: #334155; margin-bottom: 15px; border-bottom: 2px solid #e2e8f0; padding-bottom: 10px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; margin-bottom: 40px; }
.tool-grid.admin { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.tool-card { display: block; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 20px 15px; text-align: center;
             text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(0,0,0,.05); transition: transform .2s, box-shadow .2s, border-color .2s; }
.tool-card:hover { transform: translateY(-3px); box-shadow: 0 4px 12px rgba(0,0,0,.1); border-color: #93c5fd; }
.tool-card .tool-icon { font-size: 40px; margin-bottom: 10px; }
.tool-card h4 { margin: 0 0 5px; color: #1e3a8a; font-size: 16px; }
.tool-card .tool-desc { font-size: 12px; color: #64748b; }
.tool-card.admin { background: #f8fafc; border: 1px dashed #cbd5e1; padding: 15px; box-shadow: none; }
.tool-card.admin:hover { transform: none; background: #f1f5f9; border-color: #94a3b8; box-shadow: none; }
.tool-card.admin .tool-icon { font-size: 24px; margin-bottom: 8px; }
.tool-card.admin h5 { margin: 0; color: #475569; font-size: 14px; }

/* ----- 管理頁通用 ----- */
.admin-page { max-width: 1200px; margin: 20px auto; display: block; }
.admin-page h2 { color: #2c3e50; }
.card { background: #fff; padding: 20px 25px; border-radius: 8px; box-shadow: 0 0 15px rgba(0,0,0,.08); margin-bottom: 20px; }
.card h4 { margin: 0 0 8px; color: #2980b9; }
.field-label { font-weight: bold; display: block; margin-bottom: 5px; }
.card select, .card input[type=number], .card input[type=text] { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
.spec-box { margin-top: 12px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 10px 14px; font-size: 14px; }
.spec-box ul { margin: 6px 0 0; padding-left: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin-bottom: 15px; }
@media (max-width: 700px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: 6px; margin-bottom: -1px; }
.tab { padding: 8px 16px; border: 1px solid #cbd5e1; border-bottom: 0; background: #e2e8f0; border-radius: 6px 6px 0 0; cursor: pointer; font-weight: bold; color: #475569; }
.tab.active { background: #fff; color: #1e3a8a; }
input[type=file]#json_files, input[type=file]#json_folder { display: none; }
.btn-row.compact { margin-top: 10px; }
.btn-row.compact > * { flex: 0 0 auto; }
.folder-list { display: flex; flex-direction: column; gap: 6px; }
.folder-btn { text-align: left; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 6px; background: #f8fafc; cursor: pointer; font: inherit; }
.folder-btn:hover { background: #eff6ff; border-color: #93c5fd; }
.table-wrap { max-height: 420px; overflow: auto; border: 1px solid #eee; border-radius: 4px; margin: 10px 0 15px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: center; }
.data-table th { background: #343a40; color: #fff; padding: 8px; position: sticky; top: 0; }
.data-table td { padding: 6px 8px; border-bottom: 1px solid #eee; }
.diff-ok { color: #16a34a; font-weight: bold; } .diff-warn { color: #d97706; font-weight: bold; } .diff-bad { color: #dc2626; font-weight: bold; }

/* ----- 產品管理 ----- */
.admin-page.wide { max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: center; }
.flash { color: #27ae60; font-weight: bold; background: #e8f8f5; padding: 5px 10px; border-radius: 4px; }
.form-row { display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-start; }
.form-row .w1 { flex: 1; min-width: 140px; } .form-row .w2 { flex: 2; min-width: 180px; }
.form-row .field-label { font-size: 13px; }
.form-actions { display: flex; gap: 10px; width: 100%; justify-content: flex-end; }
#form_section.editing { background: #fff3cd; border: 1px solid #ffeeba; }
.group-title { border-bottom: 2px solid #eee; padding-bottom: 10px; margin: 30px 0 15px; }
.group-title small { font-size: 12px; color: #999; font-weight: normal; }
.product-table { width: 100%; border-collapse: collapse; font-size: 14px; border: 1px solid #dee2e6; background: #fff; }
.product-table th { background: #343a40; color: #fff; padding: 10px 8px; text-align: left; }
.product-table td { padding: 8px; border-bottom: 1px solid #eee; vertical-align: top; }
.product-table .c { text-align: center; }
.product-table tr.inactive { opacity: .6; background: #f9f9f9; }
.product-table code { background: #f8f9fa; padding: 2px 5px; border-radius: 3px; color: #e83e8c; font-size: 12px; }
.drag-handle { cursor: grab; color: #adb5bd; font-size: 18px; }
.drag-handle:hover { color: #2c3e50; }
.sortable-ghost { opacity: .4; background: #f1f8ff !important; }
.muted { color: #999; } .small { font-size: 11px; } .link-blue { color: #2980b9; font-weight: bold; font-size: 13px; }
.tag { padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: bold; display: inline-block; margin: 1px 0; }
.tag-on { background: #e8f8f5; color: #27ae60; } .tag-off { background: #fdedec; color: #c0392b; } .tag-info { background: #ebf5fb; color: #2980b9; }
.engine-pill { color: #fff; padding: 3px 8px; border-radius: 12px; font-size: 11px; font-weight: bold; white-space: nowrap; }
.spec-cell { font-size: 12px; color: #475569; max-width: 280px; }
.actions { white-space: nowrap; }
.btn-sm { display: inline-block; padding: 5px 8px; border: 0; border-radius: 3px; color: #fff; font-size: 12px; cursor: pointer; text-decoration: none; margin: 0 2px 5px; }
.btn-orange { background: #f39c12; } .btn-purple { background: #8e44ad; } .btn-green { background: #27ae60; font-weight: bold; }
.btn-disabled { background: #cbd5e1; cursor: not-allowed; }
.spec-dialog { margin: auto; max-height: 92vh; width: min(760px, 95vw); border: 0; border-radius: 10px; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.spec-dialog::backdrop { background: rgba(15,23,42,.5); }
.spec-dialog h3 { margin-top: 0; }
.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin-bottom: 12px; font-size: 14px; }
.spec-grid .span-2 { grid-column: span 2; }
.spec-grid input[type=text], .spec-grid input[type=number], .spec-grid select, .spec-grid textarea { width: 100%; padding: 7px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-top: 4px; }
.spec-grid fieldset { border: 1px solid #e2e8f0; border-radius: 6px; padding: 6px 10px; }
.spec-grid fieldset label { margin-right: 10px; white-space: nowrap; }
.code-area { width: 100%; font: 12px/1.5 ui-monospace, Menlo, monospace; box-sizing: border-box; margin: 8px 0; }
details summary { cursor: pointer; font-weight: bold; margin-top: 12px; }
@media (max-width: 700px) { .spec-grid { grid-template-columns: 1fr; } .spec-grid .span-2 { grid-column: auto; } }
