:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #18202a;
    --muted: #657180;
    --line: #dfe4ea;
    --primary: #176b55;
    --primary-dark: #105442;
    --primary-soft: #e8f4f0;
    --success: #25724c;
    --success-soft: #e5f3eb;
    --danger: #b43b45;
    --danger-soft: #fbeaec;
    --shadow: 0 10px 30px rgba(26, 38, 49, .1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-size: 15px; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.topbar { height: 64px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { width: min(1160px, calc(100% - 40px)); height: 100%; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 18px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; display: inline-grid; place-items: center; background: var(--primary); color: white; border-radius: 7px; font-weight: 700; }
.icon-text-button { border: 0; background: transparent; color: var(--muted); padding: 8px 4px; }
.icon-text-button:hover { color: var(--danger); }

.page-shell { width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 60px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: 28px; line-height: 1.25; }
.page-heading p { margin: 7px 0 0; color: var(--muted); }

.button { min-height: 42px; border: 1px solid transparent; border-radius: 6px; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .15s; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { background: var(--surface); color: #364251; border-color: var(--line); }
.button-secondary:hover { background: #f7f9fa; border-color: #bec7d1; }
.button-success { background: var(--success-soft); color: var(--success); border-color: #c7e4d4; }
.button-success:hover { background: #d7ecdf; }
.button-small { min-height: 36px; padding: 7px 12px; font-size: 14px; }
.button-block { width: 100%; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 6px; background: transparent; color: #5e6977; font-size: 25px; line-height: 1; display: inline-grid; place-items: center; flex: 0 0 auto; }
.icon-button:hover { background: #eef1f4; }
.icon-button.danger { color: var(--danger); }
.icon-button.danger:hover { background: var(--danger-soft); }

.alert { border: 1px solid; border-radius: 6px; padding: 12px 14px; margin-bottom: 18px; }
.alert-success { color: #175d3b; background: #edf8f2; border-color: #bfe1ce; }
.alert-error { color: #8d2630; background: #fff0f1; border-color: #edc2c6; }

.toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs { align-self: stretch; display: flex; gap: 28px; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 7px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tab span { min-width: 22px; height: 22px; padding: 0 6px; display: inline-grid; place-items: center; background: #e6eaee; border-radius: 11px; font-size: 12px; }
.tab.active { color: var(--primary); }
.tab.active::after { content: ""; position: absolute; height: 3px; left: 0; right: 0; bottom: -1px; background: var(--primary); }
.tab.active span { background: var(--primary-soft); color: var(--primary); }
.search-form { display: flex; gap: 8px; }
.search-input { width: 280px; height: 40px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0 11px; color: #88929d; }
.search-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 107, 85, .1); }
.search-input input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }

.order-list { display: grid; gap: 12px; }
.order-card { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; display: grid; grid-template-columns: minmax(0, 1fr) auto; transition: border-color .15s, box-shadow .15s; }
.order-card:hover { border-color: #c6cdd5; box-shadow: 0 4px 16px rgba(26, 38, 49, .06); }
.order-main { min-width: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; padding: 18px; }
.order-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.order-title-row h2 { margin: 0; font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.status-badge { flex: 0 0 auto; border-radius: 4px; padding: 3px 7px; font-size: 12px; font-weight: 600; }
.status-ongoing { color: #9b5f0a; background: #fff3d8; }
.status-done { color: #226b8a; background: #e6f3f8; }
.status-checked { color: #6b4e9b; background: #f0eafa; }
.status-completed { color: var(--success); background: var(--success-soft); }
.customer-name { margin: 10px 0 0; font-size: 16px; font-weight: 600; }
.order-time { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.image-strip { min-width: 0; display: flex; gap: 10px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: thin; }
.image-thumb { position: relative; width: 112px; height: 84px; flex: 0 0 auto; padding: 0; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: #eef1f4; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.zoom-hint { position: absolute; right: 5px; bottom: 5px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 4px; background: rgba(18, 26, 33, .72); color: white; font-size: 17px; opacity: 0; transition: opacity .15s; }
.image-thumb:hover .zoom-hint, .image-thumb:focus-visible .zoom-hint { opacity: 1; }
.order-actions { border-left: 1px solid var(--line); padding: 18px; display: flex; align-items: center; gap: 8px; }
.order-actions form { margin: 0; }
.status-form { display: flex; align-items: center; gap: 6px; }
.status-form select { height: 36px; min-width: 98px; border: 1px solid var(--line); border-radius: 6px; padding: 0 28px 0 10px; background: var(--surface); color: #364251; outline: 0; }
.status-form select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 107, 85, .1); }

.empty-state { min-height: 300px; display: grid; justify-items: center; align-content: center; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed #cad2da; border-radius: 7px; padding: 40px 20px; }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; background: #edf1f3; color: #7b8793; border-radius: 7px; font-size: 30px; }
.empty-state h2 { margin: 17px 0 0; color: #3f4a57; font-size: 18px; }
.empty-state p { margin: 8px 0 0; }

.modal { width: min(640px, calc(100% - 28px)); max-height: calc(100dvh - 32px); border: 0; border-radius: 8px; padding: 0; background: var(--surface); box-shadow: var(--shadow); }
.modal::backdrop, .lightbox::backdrop { background: rgba(12, 18, 23, .6); }
.modal-panel { padding: 24px; overflow-y: auto; max-height: calc(100dvh - 32px); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.modal-header h2 { margin: 0; font-size: 21px; }
.modal-header p { margin: 5px 0 0; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stack-form, .form-grid label { display: grid; gap: 7px; }
.stack-form { gap: 16px; }
.stack-form label { display: grid; gap: 7px; }
label > span, .field-label { color: #3c4652; font-weight: 600; }
label b, .upload-title b { color: var(--danger); }
input[type="text"], input[type="password"] { width: 100%; height: 44px; border: 1px solid #cfd6dd; border-radius: 6px; padding: 0 12px; background: white; color: var(--text); outline: 0; }
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 107, 85, .1); }
.upload-field { margin-top: 18px; display: grid; gap: 8px; }
.upload-field input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-box { min-height: 92px; display: grid; place-items: center; align-content: center; gap: 5px; border: 1px dashed #aeb9c3; border-radius: 6px; background: #fafbfc; color: var(--primary); text-align: center; padding: 14px; }
.upload-box:hover { border-color: var(--primary); background: #f3f9f7; }
.upload-box small { color: var(--muted); font-weight: 400; }
.preview-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.preview-item, .existing-image { position: relative; min-width: 0; aspect-ratio: 1; border-radius: 5px; overflow: hidden; background: #eef1f4; border: 1px solid var(--line); margin: 0; }
.preview-item img, .existing-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-item span, .existing-image button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border: 0; border-radius: 4px; background: rgba(18, 26, 33, .75); color: white; display: grid; place-items: center; font-size: 18px; line-height: 1; }
.field-label { display: block; margin-bottom: 8px; }
.modal-actions { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.lightbox { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; background: #11171c; color: white; overflow: hidden; }
.lightbox-toolbar { height: 58px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; gap: 15px; background: #1a2229; }
.lightbox-toolbar > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-toolbar > div { display: flex; gap: 6px; }
.lightbox-button { min-width: 38px; height: 38px; border: 1px solid #48525a; border-radius: 5px; background: #263038; color: white; font-size: 18px; }
.lightbox-button:hover { background: #35414a; }
.lightbox-stage { width: 100%; height: calc(100dvh - 58px); display: grid; place-items: center; overflow: auto; cursor: zoom-in; }
.lightbox-stage img { display: block; max-width: 92%; max-height: 88%; object-fit: contain; transform-origin: center; transition: transform .15s; }

.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: #eef2f3; }
.login-shell { width: min(390px, 100%); }
.login-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 34px; box-shadow: 0 12px 38px rgba(26, 38, 49, .08); }
.login-panel .brand-mark { width: 42px; height: 42px; margin-bottom: 18px; }
.login-panel h1 { margin: 0; font-size: 25px; }
.login-panel > p { margin: 7px 0 24px; color: var(--muted); }
.login-panel .alert { margin-top: -8px; }

@media (max-width: 820px) {
    .topbar-inner, .page-shell { width: min(100% - 28px, 1160px); }
    .page-shell { padding-top: 24px; }
    .toolbar { align-items: stretch; flex-direction: column; border-bottom: 0; gap: 14px; }
    .tabs { height: 46px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex: 0 0 auto; }
    .search-form { width: 100%; }
    .search-input { width: 100%; }
    .order-card { grid-template-columns: 1fr; }
    .order-main { grid-template-columns: 1fr; gap: 15px; }
    .order-actions { border-left: 0; border-top: 1px solid var(--line); justify-content: flex-end; padding: 12px 18px; }
}

@media (max-width: 560px) {
    .topbar { height: 58px; }
    .topbar-inner, .page-shell { width: min(100% - 24px, 1160px); }
    .page-shell { padding: 20px 0 40px; }
    .page-heading { align-items: flex-end; gap: 14px; margin-bottom: 20px; }
    .page-heading h1 { font-size: 23px; }
    .page-heading p { display: none; }
    .page-heading .button { min-height: 40px; padding: 8px 12px; }
    .tabs { gap: 20px; }
    .search-form .button { padding: 8px 13px; }
    .order-main { padding: 15px; }
    .order-actions { padding: 11px 15px; overflow-x: auto; justify-content: flex-start; }
    .image-thumb { width: 104px; height: 78px; }
    .zoom-hint { opacity: 1; }
    .modal { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
    .modal-panel { padding: 18px; max-height: calc(100dvh - 16px); }
    .form-grid { grid-template-columns: 1fr; }
    .preview-grid { grid-template-columns: repeat(4, 1fr); }
    .modal-actions { position: sticky; bottom: -18px; margin-inline: -18px; padding: 14px 18px 18px; background: white; }
    .modal-actions .button { flex: 1; }
    .lightbox-toolbar { padding: 0 10px; }
    .lightbox-toolbar > span { display: none; }
    .lightbox-toolbar > div { width: 100%; justify-content: flex-end; }
    .login-page { padding: 14px; }
    .login-panel { padding: 28px 22px; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
