/* 海燕 PWA - 扁平化样式 v4 */
:root {
  --primary: #1a5c9e;
  --primary-dark: #155082;
  --primary-light: #e8f0fa;
  --bg: #f8f9fc;
  --card: #fff;
  --text: #1a1a2e;
  --text-2: #5a5a7a;
  --text-3: #9a9ab0;
  --border: #e2e6ec;
  --success: #27ae60;
  --success-bg: #ecfdf5;
  --error: #e74c3c;
  --error-bg: #fef2f2;
  --warning: #f39c12;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ===== Login ===== */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-box {
  padding: 44px 28px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 2px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 4px;
  letter-spacing: 1px;
}

.login-line {
  width: 36px;
  height: 2px;
  background: var(--primary);
  margin: 28px auto;
}

.login-box input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.login-box input[type="text"]:focus {
  border-color: var(--primary);
  background: var(--bg);
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 2px;
  font-family: inherit;
  margin-top: 16px;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.agreement-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
}

.agreement-link:hover { color: var(--primary); }

/* ===== Main View ===== */
#main-view {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}

/* Top Bar */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 50px;
}

.top-bar .bar-title {
  flex: 1;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.top-bar .bar-logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.top-bar .bar-title-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar .bar-title:focus {
  outline: 2px solid rgba(255, 255, 255, 0.65);
  outline-offset: 2px;
}

.top-bar .menu-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 6px 4px;
  line-height: 1;
}

.top-bar .menu-btn:hover { opacity: 0.8; }

/* Install Tip */
.install-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 0;
  padding: 10px 12px;
  border: 1px solid #b6d3f0;
  border-radius: 8px;
  background: #edf5ff;
  color: #174d80;
  font-size: 12px;
}

.install-tip.hidden {
  display: none;
}

.install-tip-text {
  flex: 1;
  min-width: 0;
}

.install-tip-btn {
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.install-tip-btn:hover {
  background: var(--primary-dark);
}

.install-tip-close {
  border: none;
  background: transparent;
  color: #3e6d95;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

/* ===== Drawer ===== */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.drawer-mask.open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 60%;
  max-width: 85vw;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  background: var(--primary);
  color: #fff;
  padding: 24px 20px 18px;
}

.drawer-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.drawer-key {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 6px;
}

.drawer-balance-row {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.drawer-balance {
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.refresh-btn {
  margin-left: 8px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.refresh-btn:hover { background: rgba(255,255,255,0.3); }

.drawer-label {
  padding: 16px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 2px;
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
}

.drawer-item {
  display: flex;
  align-items: center;
  padding: 13px 20px;
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
  transition: background 0.1s;
}

.drawer-item:hover { background: #fafbfc; }
.drawer-item:active { background: #f0f2f5; }

.drawer-item .item-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.drawer-item .item-price {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  margin-left: 8px;
}

.drawer-bottom {
  padding: 12px 20px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.drawer-bottom .logout-btn {
  width: 100%;
  padding: 12px;
  background: var(--error-bg);
  color: var(--error);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.drawer-bottom .logout-btn:hover { background: #fee2e2; }

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 20px 16px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: calc(20px + var(--safe-bottom));
}

/* Welcome */
.welcome {
  text-align: center;
  padding: 40px 16px 20px;
}

.welcome-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome-desc {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 24px;
}

.welcome-balance-box {
  padding: 20px 0;
  margin-bottom: 16px;
}

.welcome-balance-label {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 4px;
}

.welcome-balance-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.welcome-agreement {
  text-align: left;
  padding: 16px 0;
}

.welcome-agreement-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome-agreement-text {
  font-size: 14px;
  color: var(--text-2);
}

.welcome-agreement-text h1,
.welcome-agreement-text h2,
.welcome-agreement-text h3,
.welcome-agreement-text h4 {
  color: var(--text);
  margin: 10px 0 6px;
}

.welcome-agreement-text p {
  margin: 6px 0;
}

.welcome-agreement-text ul {
  margin: 6px 0 6px 18px;
}

.welcome-agreement-text pre {
  background: #f3f5f8;
  padding: 10px;
  overflow-x: auto;
}

.welcome-agreement-text code {
  background: #eef1f5;
  padding: 1px 4px;
}

/* ===== Query Form ===== */
#form-area {
  padding: 12px 0;
}

.form-head {
  margin-bottom: 16px;
}

.form-head .form-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
}

.form-head .form-desc {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.field-group {
  margin-bottom: 8px;
}

.field-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 2px;
}

.field-group label.req::after {
  content: '*';
  color: var(--error);
  margin-left: 2px;
}

.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
  border-color: var(--primary);
  background: var(--bg);
}

.field-group textarea {
  resize: vertical;
  min-height: 70px;
}

.form-btns {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.form-btns .btn-primary { flex: 2; margin-top: 0; }

.btn-cancel {
  flex: 1;
  padding: 12px;
  background: var(--bg);
  color: var(--text-2);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-cancel:hover { background: #eef1f6; }

/* ===== Result Area - 热敏打印小票 ===== */
#result-area {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  font-family: 'Courier New', Courier, monospace;
}

/* 小票主体 */
.receipt {
  width: 100%;
  background-color: #fff;
  padding: 40px 20px;
  box-shadow: none;
  color: #000;
  font-size: 12px;
  line-height: 1.4;
}

.receipt-header {
  text-align: center;
  margin-bottom: 15px;
}

.receipt-header .receipt-title {
  font-size: 16px;
  font-weight: bold;
  margin: 0;
  letter-spacing: 4px;
}

.receipt-header .receipt-time {
  font-size: 11px;
  color: #666;
  margin: 5px 0 0;
}

/* 分隔线 */
.receipt-divider {
  border: none;
  border-top: 1px dashed #000;
  margin: 10px 0;
}

/* 小节标题 */
.receipt-section-title {
  font-size: 12px;
  font-weight: bold;
  padding-bottom: 5px;
  margin-bottom: 5px;
}

/* 信息行 */
.receipt-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.receipt-row .lbl {
  color: #333;
  flex-shrink: 0;
}

.receipt-row .val {
  text-align: right;
  font-weight: bold;
  word-break: break-all;
}

.receipt-row.receipt-row-block {
  display: block;
}

.receipt-row.receipt-row-block .lbl {
  display: block;
  margin-bottom: 4px;
}

.receipt-row.receipt-row-block .val {
  display: block;
  text-align: left;
}

.receipt-image-link {
  display: inline-block;
}

.receipt-image {
  width: 100%;
  max-width: 240px;
  max-height: 180px;
  object-fit: contain;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
}

.receipt-image-url {
  margin-top: 4px;
  font-size: 11px;
  font-weight: normal;
  color: #666;
  word-break: break-all;
}

.receipt-status {
  text-align: center;
  padding: 6px 0;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 2px;
}

.receipt-status.pass { color: #000; }
.receipt-status.fail { color: #000; }
.receipt-status.error { color: #000; }

.receipt-section { margin: 4px 0; }

/* 底部 */
.receipt-foot {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
  color: #666;
}

/* ===== Modal ===== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-bg.open { opacity: 1; visibility: visible; }

.modal-box {
  background: var(--bg);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  border-radius: 8px;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}

.modal-x {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-3);
  padding: 2px;
}

.modal-body {
  padding: 20px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}

.modal-body h1,
.modal-body h2,
.modal-body h3,
.modal-body h4 {
  color: var(--text);
  margin: 10px 0 6px;
}

.modal-body p {
  margin: 6px 0;
}

.modal-body ul {
  margin: 6px 0 6px 18px;
}

.modal-body pre {
  background: #f3f5f8;
  padding: 10px;
  overflow-x: auto;
}

.modal-body code {
  background: #eef1f5;
  padding: 1px 4px;
}

/* ===== Loading ===== */
.loading-bg {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s;
}

.loading-bg.show { opacity: 1; visibility: visible; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--error); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 2px; }
