:root {
  --bg: #ffffff;
  --bg2: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --sep: #e5e5ea;
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.4;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select, button { font-size: 17px; font-family: inherit; }

/* Layout */
.nav {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.nav h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.nav .left, .nav .right { display: flex; align-items: center; gap: 8px; min-width: 56px; }
.nav .right { justify-content: flex-end; }
.nav-btn {
  background: none; border: none; color: var(--blue);
  font-size: 17px; padding: 6px 4px; border-radius: 8px;
}
.nav-btn.icon { font-size: 24px; line-height: 1; padding: 2px 6px; }
.nav-btn:active { opacity: 0.5; }

.container { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(40px + var(--safe-bottom)); }

/* Segmented control */
.segment {
  display: flex; background: var(--bg2); border-radius: 9px; padding: 2px;
  margin: 4px 0 16px; border: 0.5px solid var(--sep);
}
.segment button {
  flex: 1; border: none; background: none; padding: 7px 0; border-radius: 7px;
  font-size: 15px; font-weight: 600; color: var(--text);
}
.segment button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px; display: flex; gap: 14px; align-items: flex-start;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 0.5px solid var(--sep);
}
.card:active { background: #fafafa; }
.card .ico {
  width: 44px; height: 44px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  background: var(--bg2);
}
.card .ico.trip { background: #e8f0ff; }
.card .ico.hotel { background: #eafbef; }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 600; font-size: 17px; margin: 0 0 2px; }
.card .sub { color: var(--muted); font-size: 14px; margin: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; gap: 8px; }
.card .when { color: var(--text); font-size: 14px; }
.card .countdown { color: var(--blue); font-size: 14px; font-weight: 600; flex-shrink: 0; }
.card .countdown.past { color: var(--muted); font-weight: 500; }
.card .clip { font-size: 13px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* Floating add */
.fab {
  position: fixed; right: 18px; bottom: calc(22px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 29px; background: var(--blue);
  color: #fff; border: none; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,122,255,0.4); z-index: 30;
}
.fab:active { transform: scale(0.94); }

/* Forms */
.form-group { background: var(--card); border-radius: var(--radius); border: 0.5px solid var(--sep); margin-bottom: 18px; overflow: hidden; }
.field { display: flex; flex-direction: column; padding: 9px 14px; border-bottom: 0.5px solid var(--sep); }
.field:last-child { border-bottom: none; }
.field label { font-size: 12px; color: var(--muted); margin-bottom: 2px; font-weight: 500; }
.field input, .field textarea, .field select {
  border: none; outline: none; background: none; color: var(--text);
  padding: 2px 0; width: 100%; resize: none;
}
.field textarea { min-height: 48px; }
.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin: 18px 4px 6px; font-weight: 600; }

.btn {
  display: block; width: 100%; text-align: center; border: none;
  padding: 13px; border-radius: 12px; font-size: 17px; font-weight: 600;
  background: var(--blue); color: #fff; margin-top: 8px;
}
.btn:active { opacity: 0.8; }
.btn.secondary { background: var(--bg2); color: var(--blue); }
.btn.danger { background: var(--bg2); color: var(--red); }
.btn:disabled { opacity: 0.5; }

/* Detail */
.detail-head { text-align: center; padding: 8px 0 16px; }
.detail-head .big-ico { font-size: 52px; }
.detail-head h2 { margin: 8px 0 2px; font-size: 22px; }
.detail-head .route { color: var(--muted); font-size: 16px; }
.detail-head .cd { color: var(--blue); font-weight: 600; margin-top: 6px; }
.detail-head .cd.past { color: var(--muted); }

.info-row { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 0.5px solid var(--sep); gap: 12px; }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--muted); flex-shrink: 0; }
.info-row .v { text-align: right; word-break: break-word; }

/* Attachments */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.att {
  position: relative; aspect-ratio: 1; border-radius: 11px; overflow: hidden;
  background: var(--bg2); border: 0.5px solid var(--sep);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
}
.att img { width: 100%; height: 100%; object-fit: cover; }
.att .pdf { font-size: 30px; }
.att .name { font-size: 10px; color: var(--muted); padding: 0 4px; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 11px; background: rgba(0,0,0,0.55); color: #fff; border: none; font-size: 14px; line-height: 22px; padding: 0; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.login-wrap .logo { font-size: 60px; margin-bottom: 12px; }
.login-wrap h1 { font-size: 26px; margin: 0 0 4px; }
.login-wrap p { color: var(--muted); margin: 0 0 28px; }
.login-card { width: 100%; max-width: 340px; }
.login-card input { width: 100%; padding: 14px; border-radius: 12px; border: 0.5px solid var(--sep); background: var(--bg2); outline: none; margin-bottom: 12px; }

/* Misc */
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--sep); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.analyzing { text-align: center; padding: 40px 20px; color: var(--muted); }
.analyzing .spinner { width: 34px; height: 34px; margin-bottom: 14px; }
.banner { background: #fff4e5; color: #8a5a00; border: 0.5px solid #ffe0a8; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: rgba(0,0,0,0.85); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 60; opacity: 0; transition: opacity 0.2s; }
.toast.show { opacity: 1; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.linkrow { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copybox { width: 100%; padding: 10px 12px; border-radius: 10px; border: 0.5px solid var(--sep); background: var(--bg2); font-size: 13px; word-break: break-all; }
a { color: var(--blue); text-decoration: none; }
.filepick { display: block; text-align: center; padding: 14px; border: 1.5px dashed var(--blue); border-radius: 12px; color: var(--blue); font-weight: 600; margin-bottom: 14px; }
