/* AnyOrder web — mobile-first, dark by default */

:root {
  --accent: #2aa79b;
  --accent-dim: #23897f;
  --accent-soft: rgba(42, 167, 155, 0.16);
  --bg: #0f1514;
  --surface: #1a2321;
  --surface-2: #223029;
  --surface-press: #24312e;
  --border: #2a3835;
  --text: #e8edec;
  --text-2: #93a5a1;
  --text-3: #647672;
  --danger: #e5484d;
  --red: #e5484d;
  --yellow: #f0b429;
  --green: #46a758;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  --radius: 12px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5f4;
    --surface: #ffffff;
    --surface-2: #eaf0ee;
    --surface-press: #e2ebe8;
    --border: #dde5e3;
    --text: #17211f;
    --text-2: #5e716d;
    --text-3: #8ba09b;
    --shadow: 0 2px 10px rgba(23, 33, 31, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- screen / header ---------- */

.screen { display: flex; flex-direction: column; min-height: 100dvh; }
.order-screen { height: 100dvh; overflow: hidden; }

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.order-screen header.top { position: static; }

.top-titles { flex: 1; min-width: 0; text-align: center; }
.top-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-sub {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--accent);
}
.icon-btn:active { background: var(--accent-soft); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-spacer { width: 44px; height: 44px; flex: none; }

.page {
  flex: 1;
  min-height: 0;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
}

/* ---------- controls ---------- */

.input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  background: var(--surface-2);
  width: 100%;
}
.btn:active { filter: brightness(1.12); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dim); }
.btn.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

.seg {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  flex: 1;
  min-height: 38px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.seg-wrap { padding: 10px 16px 2px; }
.order-screen .seg-wrap { padding-bottom: 10px; border-bottom: 1px solid var(--border); }

/* ---------- lists / cards ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 64px;
}
button.card:active { background: var(--surface-press); }

.card-main { flex: 1; min-width: 0; }
.card-title {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-sub {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-side { flex: none; display: flex; align-items: center; gap: 8px; }
.chevron { color: var(--text-3); flex: none; display: inline-flex; }
.chevron svg { width: 18px; height: 18px; }

.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 1.5px 6px;
  vertical-align: 2px;
  margin-left: 8px;
  white-space: nowrap;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  border: 1.5px solid var(--border);
  background: transparent;
}
.dot.c1 { background: var(--red); border-color: var(--red); }
.dot.c2 { background: var(--yellow); border-color: var(--yellow); }
.dot.c3 { background: var(--green); border-color: var(--green); }

.searchbar { padding: 10px 16px 2px; }

/* elements of order list */
.element-card { align-items: flex-start; min-height: 56px; }
.element-card .dot { margin-top: 5px; }
.el-num { font-size: 14px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.el-info { font-size: 13px; color: var(--yellow); margin-top: 3px; }
.thumb {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* info rows */
.info-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 14px;
}
.info-row { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.info-value { font-size: 15px; word-break: break-word; white-space: pre-wrap; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 18px 4px 8px;
}

.color-picker { display: flex; gap: 12px; padding: 12px 14px; }
.color-opt {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.color-opt .dot { width: 20px; height: 20px; }
.color-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
}
.login-logo { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.login-title { font-size: 28px; font-weight: 700; }
.login-sub { color: var(--text-2); margin: 6px 0 28px; }
.login-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.form-error {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- chat ---------- */

.tab-body { flex: 1; min-height: 0; position: relative; }
.tab-panel { position: absolute; inset: 0; overflow-y: auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); display: none; }
.tab-panel.active { display: block; }
.tab-panel.chat-panel { display: none; padding: 0; overflow: hidden; }
.tab-panel.chat-panel.active { display: flex; flex-direction: column; }

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 82%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-author { font-size: 12px; font-weight: 600; color: var(--accent); margin: 2px 6px 2px 10px; }
.bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  padding: 9px 12px;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
}
.msg.mine .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-radius: 16px;
  border-bottom-right-radius: 6px;
}
.msg.pending .bubble { opacity: 0.65; }
.msg-meta { font-size: 11px; color: var(--text-3); margin: 3px 8px 0; }

.bubble.media { padding: 4px; overflow: hidden; }
.msg-img { display: block; max-width: 100%; max-height: 260px; border-radius: 12px; cursor: pointer; }
.img-placeholder {
  width: 200px;
  height: 140px;
  border-radius: 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-card { display: flex; align-items: center; gap: 10px; min-width: 190px; padding: 6px 8px; text-align: left; }
.file-icon {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg.mine .file-icon { background: rgba(255, 255, 255, 0.22); color: #fff; }
.file-icon svg { width: 22px; height: 22px; }
.file-name { font-size: 14px; font-weight: 600; word-break: break-word; }
.file-size { font-size: 12px; opacity: 0.75; }

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer .input { flex: 1; min-height: 44px; border-radius: 22px; }
.composer .icon-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 50%; }
.composer .icon-btn.send { background: var(--accent); border-color: var(--accent); color: #fff; }
.composer .icon-btn:disabled { opacity: 0.5; }

.day-sep { align-self: center; font-size: 12px; color: var(--text-3); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px 10px; margin: 6px 0 2px; }

/* ---------- misc ---------- */

.loader { display: flex; justify-content: center; padding: 44px 0; }

.spinner {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner.sm { width: 15px; height: 15px; border-width: 2px; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 24px; color: var(--text-2); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-sub { font-size: 14px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: min(92vw, 480px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 14.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--danger); color: var(--danger); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
