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

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --bg: #f0f2f5;
    --card-bg: #fff;
    --text: #333;
    --text-muted: #666;
    --border: #e0e0e0;
    --danger: #d93025;
    --success: #0d904f;
    --warning: #f9ab00;
    --sidebar-w: 260px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

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

.sidebar {
    width: var(--sidebar-w);
    background: #1e293b;
    color: #cbd5e1;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-header h2 { color: #fff; font-size: 18px; }

main {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 24px;
    min-height: 100vh;
}

/* ===== Navigation ===== */
.nav-list { list-style: none; }
.nav-item { border-bottom: 1px solid rgba(255,255,255,.05); }
.nav-item > a, .nav-item > span {
    display: block;
    padding: 12px 20px;
    color: #cbd5e1;
    transition: background .2s;
}
.nav-item > a:hover, .nav-item.active > a {
    background: rgba(255,255,255,.1);
    color: #fff;
    text-decoration: none;
}
.nav-item.active > a { border-left: 3px solid var(--primary); }

.nav-sub { list-style: none; display: none; }
.nav-parent.open > .nav-sub { display: block; }
.nav-sub li a {
    display: block;
    padding: 10px 20px 10px 36px;
    color: #94a3b8;
    font-size: 14px;
}
.nav-sub li a:hover, .nav-sub li.active a { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }

.nav-toggle::after { content: ' ▼'; font-size: 10px; float: right; }
.nav-parent.open > .nav-toggle::after { content: ' ▲'; }

.nav-badge { padding: 12px 20px; }
.nav-badge span { font-size: 13px; }
.nav-badge strong { color: #fbbf24; font-size: 18px; margin-left: 4px; }

.nav-search { padding: 12px 16px; }
.search-form { display: flex; gap: 4px; }
.search-form input {
    flex: 1; padding: 6px 10px; border: 1px solid rgba(255,255,255,.2);
    border-radius: 4px; background: rgba(255,255,255,.1); color: #fff; font-size: 13px;
}
.search-form input::placeholder { color: #94a3b8; }
.search-form button {
    padding: 6px 10px; background: var(--primary); color: #fff;
    border: none; border-radius: 4px; cursor: pointer; font-size: 13px;
}

/* ===== Page Header ===== */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; color: #1e293b; }

/* ===== Buttons ===== */
.btn {
    display: inline-block; padding: 8px 16px; border: none; border-radius: var(--radius);
    cursor: pointer; font-size: 14px; transition: all .2s; text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* ===== Cards ===== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.trip-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform .2s, box-shadow .2s;
}
.trip-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }

.card-img {
    width: 100%; height: 160px; object-fit: cover; display: block;
    background: #e0e0e0;
}

.card-body { padding: 12px 16px; }

.card-order {
    font-size: 14px; font-weight: 600; color: var(--primary);
    display: inline-flex; align-items: center; gap: 5px; margin-bottom: 6px;
}
.card-order:hover { text-decoration: underline; }

.card-status-icon {
    display: inline-block; width: 16px; height: 16px; line-height: 16px;
    font-size: 10px; text-align: center; border-radius: 3px;
    color: #fff; font-weight: 700; flex-shrink: 0;
}
.card-status-icon.changed { background: #e37400; }
.card-status-icon.refunded { background: #d93025; }

.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }

.badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 11px; background: #e8f0fe; color: #1a73e8;
    white-space: nowrap;
}
.badge-gray { background: #f1f3f4; color: #5f6368; }
.badge-green { background: #e6f4ea; color: #0d904f; }
.badge-orange { background: #fef7e0; color: #e37400; }
.badge-red { background: #fce8e6; color: #d93025; }

.card-price {
    font-size: 18px; font-weight: 700; color: #e37400;
    display: inline-flex; align-items: center; gap: 4px;
}
.card-price-icon { font-size: 14px; }

.card-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

/* ===== Pagination ===== */
.pagination {
    display: flex; justify-content: center; gap: 4px; margin-top: 32px; flex-wrap: wrap;
}
.pagination a {
    display: inline-block; padding: 8px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: 14px;
    background: #fff; transition: all .2s;
}
.pagination a:hover { background: var(--primary); color: #fff; text-decoration: none; border-color: var(--primary); }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination a.disabled { opacity: .4; pointer-events: none; }

/* ===== Forms ===== */
.form-container { max-width: 700px; background: var(--card-bg); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow); }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; color: #333; }
.form-group label .required { color: var(--danger); margin-left: 2px; }

.form-control {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 14px; transition: border-color .2s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Checkbox/Toggle ===== */
.checkbox-group { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.checkbox-group input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

.points-input { display: none; margin-top: 8px; }
.points-input.show { display: block; }

/* ===== Detail Page ===== */
.detail-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 24px;
}

.detail-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}
.detail-section.full { grid-column: 1 / -1; }

/* Screenshot spans both rows on the right */
.detail-screenshot {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
}
.detail-screenshot h3 { flex-shrink: 0; }
.screenshot-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.detail-section h3 {
    font-size: 16px; margin-bottom: 16px; padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
}
.detail-table { width: 100%; }
.detail-table th, .detail-table td { padding: 10px 0; border-bottom: 1px solid #f0f0f0; text-align: left; }
.detail-table th { width: 120px; color: var(--text-muted); font-weight: 500; font-size: 13px; }
.detail-table td { font-size: 14px; }

/* 2-column order info table */
.detail-table-2col th { width: 70px; }
.detail-table-2col th:nth-child(3) { width: 70px; }
.detail-table-2col td:nth-child(2) { padding-right: 16px; }

.detail-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* Trip association + change history side by side */
.related-change-row {
    display: flex;
    gap: 32px;
}
.related-change-col {
    flex: 1;
    min-width: 0;
}
.related-change-col h3 {
    font-size: 16px; margin-bottom: 16px; padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
}

/* Change history list */
.change-history-list {
    max-height: 240px;
    overflow-y: auto;
}
.change-history-item {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 14px;
}
.change-detail {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}
.change-time {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

/* ===== Screenshot in detail ===== */
.screenshot-thumb {
    max-width: 100%; max-height: 400px; border-radius: var(--radius);
    cursor: pointer; transition: opacity .2s; object-fit: contain;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.screenshot-thumb:hover { opacity: .8; }
.screenshot-info {
    margin-top: 10px; font-size: 12px; color: #999; text-align: center;
}
.screenshot-empty {
    color: #999; text-align: center; padding: 40px;
}
.screenshot-upload {
    margin-top: auto; padding-top: 16px; text-align: center;
}

/* ===== Modal ===== */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85);
    z-index: 1000; align-items: center; justify-content: center; cursor: zoom-out;
    flex-direction: column;
}
.modal-overlay.show { display: flex; }
.modal-overlay img {
    max-width: 95vw; max-height: 85vh; cursor: default;
    transition: transform .2s ease; object-fit: contain;
}

.modal-toolbar {
    display: flex; gap: 8px; margin-bottom: 12px;
}
.modal-toolbar button {
    width: 40px; height: 40px; border: 2px solid #fff; border-radius: 50%;
    background: rgba(255,255,255,.15); color: #fff; font-size: 18px;
    cursor: pointer; transition: background .2s;
}
.modal-toolbar button:hover { background: rgba(255,255,255,.3); }

/* ===== Flash Message ===== */
.flash-msg {
    padding: 12px 20px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: 14px; transition: opacity .3s;
}
.flash-success { background: #e6f4ea; color: #0d904f; border: 1px solid #a8dab5; }
.flash-error { background: #fce8e6; color: #d93025; border: 1px solid #f5c6c2; }

/* ===== Stats Page ===== */
.stats-top {
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; text-align: center;
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.chart-row .chart-box {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
}
.chart-box.full { grid-column: 1 / -1; }
.chart-box h3 { font-size: 16px; margin-bottom: 16px; }

.yearly-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.yearly-table th,
.yearly-table td { padding: 10px 14px; text-align: center; border-bottom: 1px solid var(--border); }
.yearly-table th { background: #f5f7fa; font-weight: 600; color: var(--text-muted); font-size: 13px; position: sticky; top: 0; }
.yearly-table tbody tr:hover { background: #f8f9fb; }
.yearly-table tbody tr:last-child td { border-bottom: 2px solid var(--primary); font-weight: 600; }

/* ===== View Page ===== */
.view-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
.view-card {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px;
}
.view-card h3 { font-size: 18px; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 2px solid var(--primary); }
.view-card .item-list { list-style: none; }
.view-card .item-list li {
    padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 14px;
    display: flex; justify-content: space-between;
}

/* ===== Entity Detail View ===== */
.entity-detail {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}
.entity-detail h2 {
    font-size: 22px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
}
.entity-detail .detail-table th {
    width: 180px;
}
.entity-section {
    margin-bottom: 24px;
}
.entity-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
}

/* 3-column detail grid */
.detail-grid-3col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.detail-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 18px;
    background: var(--card-bg);
}
.detail-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}
.detail-value {
    font-size: 15px;
    color: var(--text);
    font-weight: 600;
}
.entity-images {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.entity-images img {
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.entity-stops {
    width: 100%;
    border-collapse: collapse;
}
.entity-stops th,
.entity-stops td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}
.entity-stops th {
    background: #fafafa;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
}
.entity-stops tr:hover td {
    background: #fafbfc;
}
.entity-related-link {
    color: var(--primary);
    text-decoration: none;
}
.entity-related-link:hover {
    text-decoration: underline;
}

/* ===== Minimalist Card List (Refund / Change History) ===== */
.refund-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.refund-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.refund-card-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 14px;
}
.refund-label {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
    min-width: 70px;
}
.refund-value {
    text-align: right;
    color: var(--text);
    word-break: break-all;
}
.refund-card-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

/* ===== Settings Table ===== */
.table-container { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-toolbar { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
table th { padding: 12px 16px; text-align: left; font-size: 13px; font-weight: 600; color: var(--text-muted); background: #fafafa; border-bottom: 1px solid var(--border); }
table td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
table tr:hover td { background: #fafbfc; }
table .actions { white-space: nowrap; }
table .actions .btn + .btn { margin-left: 8px; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state p { font-size: 16px; }

/* ===== Mobile: Hamburger & Sidebar ===== */
.hamburger {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 200;
    width: 36px; height: 36px; padding: 6px;
    background: var(--primary); border: none; border-radius: 6px;
    cursor: pointer; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
}
.hamburger span {
    display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px;
}

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 149;
}
.sidebar-overlay.show { display: block; }

.sidebar-close {
    display: none;
    position: absolute; top: 12px; right: 16px;
    background: none; border: none; color: #fff; font-size: 28px;
    cursor: pointer; line-height: 1; padding: 0;
}

/* ===== Milestones ===== */
.milestone-overview {
    display: flex; align-items: center; gap: 24px;
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px;
}
.milestone-overview-ring {
    position: relative; width: 120px; height: 120px; flex-shrink: 0;
}
.milestone-ring-svg {
    width: 100%; height: 100%;
}
.milestone-ring-text {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.milestone-ring-num {
    font-size: 22px; font-weight: 700; color: #0d904f;
}
.milestone-ring-label {
    font-size: 12px; color: var(--text-muted);
}
.milestone-overview-info h2 {
    margin: 0 0 4px 0; font-size: 20px;
}
.milestone-overview-info p {
    margin: 0 0 12px 0; color: var(--text-muted); font-size: 14px;
}
.milestone-overview-bar {
    height: 8px; background: #e8f0fe; border-radius: 4px; overflow: hidden;
}
.milestone-overview-fill {
    height: 100%; background: #0d904f; border-radius: 4px; transition: width .6s ease;
}

/* Milestone grid: 2-column cards */
.milestone-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px;
}
.milestone-card {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
    border-left: 4px solid var(--primary);
    transition: border-color .3s;
}
.milestone-card.milestone-done {
    border-left-color: #0d904f;
}
.milestone-card-top {
    display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.milestone-card-icon { font-size: 28px; }
.milestone-card-title h3 {
    margin: 0; font-size: 16px;
}
.milestone-card-stats {
    display: flex; align-items: baseline; gap: 4px; margin-bottom: 8px;
}
.milestone-current {
    font-size: 28px; font-weight: 700; color: var(--primary);
}
.milestone-done .milestone-current { color: #0d904f; }
.milestone-unit {
    font-size: 14px; color: var(--text-muted);
}
.milestone-next {
    font-size: 13px; color: var(--text-muted); margin-bottom: 10px;
}
.milestone-next-val {
    margin-left: 8px; color: var(--text); font-weight: 500;
}
.milestone-max {
    color: #0d904f !important; font-weight: 500;
}

/* Progress bar */
.milestone-progress {
    height: 8px; background: #e8f0fe; border-radius: 4px; overflow: hidden; margin-bottom: 4px;
}
.milestone-bar {
    height: 100%; background: var(--primary); border-radius: 4px;
    transition: width .6s ease; min-width: 2px;
}
.milestone-bar-done {
    background: #0d904f;
}
.milestone-pct {
    font-size: 12px; color: var(--text-muted); text-align: right; margin-bottom: 14px;
}

/* Tier list */
.milestone-tiers {
    border-top: 1px solid var(--border); padding-top: 12px;
}
.milestone-tier {
    display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px;
}
.milestone-tier.reached {
    color: #0d904f;
}
.milestone-tier-icon { font-size: 14px; flex-shrink: 0; }
.milestone-tier-name { flex: 1; }
.milestone-tier-goal { color: var(--text-muted); font-size: 12px; }
.milestone-tier.reached .milestone-tier-goal { color: #0d904f; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .hamburger { display: flex; }
    .sidebar-close { display: block; }

    .sidebar {
        transform: translateX(-100%);
        position: fixed; top: 0; left: 0; bottom: 0;
        width: 260px; z-index: 150;
        transition: transform .25s ease;
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-header { display: flex; justify-content: space-between; align-items: center; }

    main { margin-left: 0; padding: 16px; padding-top: 56px; }

    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .milestone-grid { grid-template-columns: 1fr; }
    .milestone-overview { flex-direction: column; text-align: center; }
    .detail-grid, .chart-row, .view-cards { grid-template-columns: 1fr; }
    .related-change-row { flex-direction: column; }
    .form-row { grid-template-columns: 1fr; }
    .stats-top { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .card-grid { grid-template-columns: 1fr; }
    .stats-top { grid-template-columns: repeat(2, 1fr); }
    .table-container { overflow-x: auto; }
    table { min-width: 600px; }
}
