/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:        #f2f2f7;
  --surface:   #ffffff;
  --accent:    #007aff;
  --accent-dk: #0062cc;
  --danger:    #ff3b30;
  --success:   #34c759;
  --warning:   #ff9500;
  --txt:       #1c1c1e;
  --txt2:      #6c6c70;
  --txt3:      #aeaeb2;
  --border:    #e5e5ea;
  --shadow:    rgba(0,0,0,0.09);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px;
  --sp-xs:4px; --sp-sm:8px; --sp-md:16px; --sp-lg:24px; --sp-xl:32px;
  --trans: 0.18s ease;
}

html { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { background: var(--bg); color: var(--txt); min-height: 100dvh; overflow-x: hidden; }
#app { max-width: 620px; margin: 0 auto; min-height: 100dvh; position: relative; }

h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 600; }
p  { line-height: 1.55; }
em { color: var(--txt2); font-style: italic; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 12px 20px;
  border: none; border-radius: var(--r-md);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: all var(--trans); min-height: 48px;
  text-decoration: none; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dk); }
.btn-secondary { background: var(--surface); color: var(--accent); border: 1.5px solid var(--border); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-ghost    { background: transparent; color: var(--accent); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 8px 14px; font-size: 14px; min-height: 36px; }
.btn-icon     { padding: 8px; min-height: 44px; min-width: 44px; border-radius: var(--r-sm); }
.flex-1       { flex: 1; }

/* ─── Header ─── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px var(--sp-md);
  display: flex; align-items: center; gap: var(--sp-sm);
  min-height: 52px;
}
.header-title { flex: 1; font-size: 17px; font-weight: 700; }
.header-back {
  display: flex; align-items: center; gap: 2px;
  color: var(--accent); font-size: 17px; font-weight: 500;
  cursor: pointer; padding: 4px; min-height: 44px; min-width: 44px;
}

/* ─── Layout helpers ─── */
.content { padding: var(--sp-md); }
.section { margin-bottom: var(--sp-lg); }
.section-title {
  font-size: 12px; font-weight: 700; color: var(--txt2);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: var(--sp-sm); padding: 0 2px;
}
.card { background: var(--surface); border-radius: var(--r-lg); padding: var(--sp-md); box-shadow: 0 1px 4px var(--shadow); }
.safe-top    { padding-top: max(0px, env(safe-area-inset-top)); }
.safe-bottom { padding-bottom: max(var(--sp-md), env(safe-area-inset-bottom)); }

/* ─── Home Selector ─── */
.homes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-md); padding: var(--sp-md); }
.home-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: var(--sp-lg) var(--sp-md);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: pointer; transition: all var(--trans);
  display: flex; flex-direction: column; align-items: center;
  gap: var(--sp-sm); text-align: center; min-height: 120px;
  justify-content: center; position: relative;
}
.home-card:active { transform: scale(0.96); }
.home-card-icon  { font-size: 36px; line-height: 1; }
.home-card-name  { font-size: 15px; font-weight: 700; color: var(--txt); }
.home-card-add   { border: 2px dashed var(--border); background: transparent; box-shadow: none; }
.home-card-add:active { background: rgba(0,122,255,0.04); }
.home-card-menu  {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,0.06); border: none; border-radius: 50%;
  width: 30px; height: 30px; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--txt2);
}
.setup-badge {
  font-size: 11px; font-weight: 600; background: #fff3e0;
  color: var(--warning); border-radius: 99px; padding: 2px 8px;
}

/* ─── Search ─── */
.search-container { padding: var(--sp-sm) var(--sp-md); background: var(--surface); border-bottom: 1px solid var(--border); }
.search-input-wrap { display: flex; align-items: center; background: var(--bg); border-radius: var(--r-md); padding: 0 12px; gap: 8px; }
.search-icon   { color: var(--txt3); font-size: 17px; }
.search-input  { flex: 1; border: none; background: transparent; padding: 11px 0; font-size: 16px; color: var(--txt); outline: none; }
.search-input::placeholder { color: var(--txt3); }
.search-ai-indicator { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: 0.4px; padding: 2px 2px 4px; min-height: 18px; transition: opacity 0.2s; }

/* ─── Action row ─── */
.action-row { display: flex; gap: var(--sp-sm); padding: var(--sp-sm) var(--sp-md) var(--sp-md); }
.action-btn {
  flex: 1; background: var(--surface); border: none; border-radius: var(--r-md);
  padding: var(--sp-md); display: flex; flex-direction: column;
  align-items: center; gap: var(--sp-xs); cursor: pointer;
  transition: all var(--trans); box-shadow: 0 1px 3px var(--shadow);
}
.action-btn:active { transform: scale(0.96); }
.action-btn-icon  { font-size: 26px; }
.action-btn-label { font-size: 14px; font-weight: 600; color: var(--txt); }

/* ─── FAB ─── */
.fab {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom, 24px)); right: 20px;
  width: 58px; height: 58px; border-radius: 29px;
  background: var(--accent); color: #fff; border: none; font-size: 28px;
  cursor: pointer; box-shadow: 0 4px 18px rgba(0,122,255,0.38);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--trans); z-index: 50;
}
.fab:active { transform: scale(0.93); }

/* ─── Item cards ─── */
.item-list { display: flex; flex-direction: column; gap: var(--sp-sm); }
.item-card {
  background: var(--surface); border-radius: var(--r-md);
  padding: var(--sp-md); display: flex; gap: var(--sp-md);
  align-items: flex-start; cursor: pointer;
  transition: all var(--trans); box-shadow: 0 1px 3px var(--shadow);
}
.item-card:active { transform: scale(0.99); }
.item-photo { width: 68px; height: 68px; border-radius: var(--r-sm); object-fit: cover; flex-shrink: 0; background: var(--bg); }
.item-photo-placeholder { width: 68px; height: 68px; border-radius: var(--r-sm); background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 30px; flex-shrink: 0; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 16px; font-weight: 700; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-purpose { font-size: 13px; color: var(--txt2); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-location { font-size: 12px; color: var(--accent); font-weight: 600; }

/* ─── List (browse) ─── */
.list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: 0 1px 3px var(--shadow); }
.list-item { display: flex; align-items: center; padding: var(--sp-md); border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--trans); min-height: 54px; }
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--bg); }
.list-item-icon  { font-size: 22px; margin-right: var(--sp-md); }
.list-item-label { flex: 1; font-size: 16px; font-weight: 500; }
.list-item-count { font-size: 13px; color: var(--txt3); margin-right: 8px; }
.list-item-arrow { color: var(--txt3); font-size: 17px; }

/* ─── Forms ─── */
.form-group { margin-bottom: var(--sp-md); }
.form-label { display: block; font-size: 13px; font-weight: 700; color: var(--txt2); margin-bottom: var(--sp-xs); text-transform: uppercase; letter-spacing: 0.4px; }
.form-input, .form-textarea, .form-select {
  width: 100%; padding: 13px var(--sp-md);
  border: 1.5px solid var(--border); border-radius: var(--r-md);
  font-size: 16px; color: var(--txt); background: var(--surface);
  outline: none; transition: border-color var(--trans);
  font-family: inherit;
}
.form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--accent); }
.form-textarea { resize: none; line-height: 1.5; }
.form-select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23aeaeb2' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }

/* ─── Photo upload ─── */
.photo-upload {
  border: 2px dashed var(--border); border-radius: var(--r-lg);
  padding: var(--sp-xl); text-align: center; cursor: pointer;
  transition: all var(--trans); background: var(--surface);
  display: block;
}
.photo-upload:active, .photo-upload:hover { border-color: var(--accent); background: rgba(0,122,255,0.03); }
.photo-upload-icon { font-size: 52px; display: block; margin-bottom: var(--sp-sm); }
.photo-upload-text { font-size: 16px; color: var(--txt2); font-weight: 500; }
.photo-upload-hint { font-size: 13px; color: var(--txt3); margin-top: 4px; }
.photo-preview-container { position: relative; border-radius: var(--r-lg); overflow: hidden; }
.photo-preview { width: 100%; max-height: 300px; object-fit: cover; display: block; }
.photo-remove-btn { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.55); color: #fff; border: none; border-radius: 50%; width: 34px; height: 34px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* ─── Progress ─── */
.progress-container { padding: 4px 0; }
.progress-bar-wrap { background: var(--border); border-radius: 99px; height: 8px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.progress-label { font-size: 14px; color: var(--txt2); text-align: center; }

/* ─── Tree editor ─── */
.tree-editor { display: flex; flex-direction: column; gap: var(--sp-sm); }
.tree-room { background: var(--surface); border-radius: var(--r-md); overflow: hidden; box-shadow: 0 1px 3px var(--shadow); }
.tree-room-header { display: flex; align-items: center; padding: 13px var(--sp-md); background: #eef4ff; gap: var(--sp-sm); }
.tree-room-name { flex: 1; font-size: 16px; font-weight: 700; color: var(--accent); }
.tree-areas { padding: var(--sp-sm) var(--sp-sm) var(--sp-sm) 20px; display: flex; flex-direction: column; gap: 6px; }
.tree-area { background: var(--bg); border-radius: var(--r-sm); overflow: hidden; }
.tree-area-header { display: flex; align-items: center; padding: 10px var(--sp-md); gap: 8px; }
.tree-area-name { flex: 1; font-size: 15px; font-weight: 600; }
.tree-spots { padding: 4px 8px 6px 20px; display: flex; flex-direction: column; gap: 4px; }
.tree-spot { display: flex; align-items: center; padding: 7px var(--sp-md); background: var(--surface); border-radius: 6px; gap: 8px; }
.tree-spot-name { flex: 1; font-size: 14px; }
.tree-edit-btn { background: none; border: none; color: var(--txt3); cursor: pointer; padding: 4px; font-size: 15px; border-radius: 4px; min-width: 28px; min-height: 28px; display: flex; align-items: center; justify-content: center; }
.tree-edit-btn:hover { background: rgba(0,0,0,0.06); }
.tree-edit-btn.delete { color: var(--danger); }
.tree-add-btn { display: flex; align-items: center; gap: 4px; color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px var(--sp-md); border: none; background: none; cursor: pointer; }

/* ─── Modals ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.46); z-index: 200;
  display: flex; align-items: flex-end; padding: var(--sp-sm);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-overlay.center { align-items: center; justify-content: center; }
.modal {
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) var(--r-md) var(--r-md);
  width: 100%; max-width: 520px; overflow: hidden;
  animation: slideUp 0.28s ease;
}
.modal.center-modal { border-radius: var(--r-xl); animation: popIn 0.22s ease; max-width: 340px; }
@keyframes slideUp { from { transform: translateY(110%); } to { transform: translateY(0); } }
@keyframes popIn   { from { opacity:0; transform:scale(0.93); } to { opacity:1; transform:scale(1); } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto 0; }
.modal-header { padding: var(--sp-md) var(--sp-md) var(--sp-sm); display: flex; align-items: center; gap: 8px; }
.modal-title  { flex: 1; font-size: 18px; font-weight: 700; }
.modal-close  { background: var(--bg); border: none; border-radius: 50%; width: 30px; height: 30px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--txt2); }
.modal-body   { padding: 4px var(--sp-md) var(--sp-md); }
.modal-footer { padding: 4px var(--sp-md) max(var(--sp-md), env(safe-area-inset-bottom, var(--sp-md))); display: flex; gap: var(--sp-sm); }

/* ─── Alerts ─── */
.alert { background: var(--surface); border-radius: var(--r-md); padding: var(--sp-md); display: flex; gap: var(--sp-md); align-items: flex-start; border: 1.5px solid var(--border); }
.alert-warning { border-color: var(--warning); background: rgba(255,149,0,0.07); }
.alert-info    { border-color: #cce4ff; background: rgba(0,122,255,0.05); }
.alert-icon    { font-size: 22px; flex-shrink: 0; line-height: 1.2; }
.alert-content { flex: 1; }
.alert-title   { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.alert-text    { font-size: 14px; color: var(--txt2); line-height: 1.5; }
.mb-md { margin-bottom: var(--sp-md); }

/* ─── Loading ─── */
.loading-overlay { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-md); padding: var(--sp-xl); text-align: center; }
.spinner { width: 42px; height: 42px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── API key screen ─── */
.api-key-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100dvh; padding: var(--sp-xl); text-align: center; gap: var(--sp-lg); }
.api-key-icon { font-size: 68px; }

/* ─── Guide steps ─── */
.guide-steps { list-style: none; display: flex; flex-direction: column; gap: var(--sp-sm); }
.guide-step { display: flex; gap: var(--sp-md); align-items: flex-start; padding: var(--sp-md); background: var(--surface); border-radius: var(--r-md); }
.guide-step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.guide-step-text { flex: 1; font-size: 15px; padding-top: 3px; line-height: 1.4; }

/* ─── Browse breadcrumb ─── */
.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--txt2); flex-wrap: wrap; padding-bottom: 10px; }
.breadcrumb-item { cursor: pointer; color: var(--accent); font-weight: 500; }
.breadcrumb-item:last-child { color: var(--txt); cursor: default; }
.breadcrumb-sep { color: var(--txt3); }

/* ─── Settings ─── */
.settings-list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: 0 1px 3px var(--shadow); }
.settings-item { display: flex; align-items: center; padding: var(--sp-md); border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--trans); min-height: 54px; }
.settings-item:last-child { border-bottom: none; }
.settings-item:active { background: var(--bg); }
.settings-item-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-right: var(--sp-md); }
.settings-item-label { flex: 1; font-size: 16px; font-weight: 500; }
.settings-item-value { font-size: 13px; color: var(--txt3); margin-right: 8px; }
.settings-item-arrow { color: var(--txt3); font-size: 16px; }

/* ─── Empty state ─── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--sp-xl) var(--sp-lg); text-align: center; gap: var(--sp-md); min-height: 220px; }
.empty-icon  { font-size: 52px; }
.empty-title { font-size: 18px; font-weight: 700; }
.empty-text  { font-size: 15px; color: var(--txt2); }

/* ─── Google Drive bar ─── */
.drive-bar {
  display: flex; align-items: center; gap: var(--sp-sm);
  margin: 0 var(--sp-md) var(--sp-sm);
  padding: 12px var(--sp-md);
  border-radius: var(--r-md); border: 1.5px solid var(--border);
  background: var(--surface);
}
.drive-bar--on   { border-color: #cce4ff; background: rgba(0,122,255,0.04); }
.drive-bar--warn { border-color: #ffe0b2; background: rgba(255,149,0,0.06); }
.drive-bar-icon  { font-size: 22px; flex-shrink: 0; }
.drive-bar-info  { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.drive-bar-title { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 5px; }
.drive-bar-sub   { font-size: 12px; color: var(--txt2); }

/* status dot */
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-ok    { background: var(--success); }
.dot-error { background: var(--danger); }
.dot-pulse { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* Drive setup modal steps */
.drive-setup-steps { padding-left: var(--sp-lg); display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.5; color: var(--txt); }
.drive-setup-steps ul { margin-top: 4px; padding-left: var(--sp-md); display: flex; flex-direction: column; gap: 3px; }
.drive-setup-steps code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; }

/* ─── Export / Import bar ─── */
.data-bar {
  display: flex; gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md) max(var(--sp-lg), env(safe-area-inset-bottom, var(--sp-lg)));
  border-top: 1px solid var(--border); margin-top: var(--sp-sm);
}
.data-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px; border-radius: var(--r-md); cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--txt2);
  background: var(--surface); border: 1.5px solid var(--border);
  transition: all var(--trans); user-select: none; -webkit-user-select: none;
}
.data-btn:active { background: var(--bg); color: var(--accent); border-color: var(--accent); }

/* ─── Move item modal ─── */
.move-divider { display:flex; align-items:center; gap:var(--sp-sm); font-size:12px; font-weight:700; color:var(--txt3); text-transform:uppercase; letter-spacing:0.5px; margin:var(--sp-md) 0; }
.move-divider::before, .move-divider::after { content:''; flex:1; height:1px; background:var(--border); }

/* ─── Utility ─── */
.hidden          { display: none !important; }
.text-center     { text-align: center; }
.text-sm         { font-size: 14px; }
.text-muted      { color: var(--txt2); }
.text-danger     { color: var(--danger); }
.text-accent     { color: var(--accent); }
.mt-sm           { margin-top: var(--sp-sm); }
.mt-md           { margin-top: var(--sp-md); }
.mt-lg           { margin-top: var(--sp-lg); }
.mb-md           { margin-bottom: var(--sp-md); }
.font-bold       { font-weight: 700; }
