@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #1c2330;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --amber:     #f0a500;
  --amber-dim: #c47f00;
  --amber-glow:rgba(240,165,0,.25);
  --red:       #f85149;
  --green:     #3fb950;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.5);
}

html { height: 100%; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── SCROLLBAR ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ─── VIEWS ─────────────────────────────────────── */
.view { display: none; flex-direction: column; min-height: 100vh; }
.view.active { display: flex; }

/* ─── HEADER ─────────────────────────────────────── */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  gap: 12px;
}
.logo { font-size: 20px; font-weight: 800; color: var(--amber); letter-spacing: -.5px; }
.logo span { color: var(--text); font-weight: 400; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ─── BUTTONS ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: all .18s; white-space: nowrap;
}
.btn-primary {
  background: var(--amber); color: #0d1117;
  box-shadow: 0 0 0 0 var(--amber-glow);
}
.btn-primary:hover {
  background: #ffb820;
  box-shadow: 0 0 0 6px var(--amber-glow), 0 2px 12px rgba(240,165,0,.4);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); border-color: #484f58; }
.btn-danger {
  background: transparent; color: var(--red);
  border: 1px solid transparent;
}
.btn-danger:hover { background: rgba(248,81,73,.12); border-color: var(--red); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted); transition: all .15s;
}
.btn-icon:hover { background: rgba(248,81,73,.12); color: var(--red); }

/* dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); min-width: 200px;
  box-shadow: var(--shadow); z-index: 200; overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: block; width: 100%; padding: 10px 16px;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--text);
  text-align: left; transition: background .15s;
}
.dropdown-item:hover { background: var(--bg3); }
.dropdown-item .item-desc { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; }

/* ─── MAIN CONTAINER ─────────────────────────────── */
.main { flex: 1; padding: 28px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ─── DASHBOARD ──────────────────────────────────── */
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 20px; }
.page-title span { color: var(--muted); font-size: 15px; font-weight: 400; margin-left: 8px; }

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
  cursor: pointer; transition: all .2s;
  display: flex; flex-direction: column; gap: 8px;
}
.project-card:hover {
  border-color: var(--amber-dim);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,.4), 0 0 0 1px var(--amber-dim);
}
.project-card-top {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.project-card-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.project-address { font-size: 12px; color: var(--muted); }
.project-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.project-total { font-size: 22px; font-weight: 800; color: var(--amber); margin-top: 4px; letter-spacing: -.5px; }
.project-rooms { font-size: 11px; color: var(--muted); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center; padding: 80px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty-icon { font-size: 52px; filter: grayscale(1); opacity: .4; }
.empty-state h2 { font-size: 20px; font-weight: 700; }
.empty-state p { color: var(--muted); max-width: 340px; }

/* ─── EDITOR ─────────────────────────────────────── */
.editor-wrap { display: flex; flex: 1; overflow: hidden; }

.rooms-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-title {
  padding: 16px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.room-tab {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s; gap: 6px;
}
.room-tab:hover { background: var(--bg3); }
.room-tab.active { background: var(--bg3); border-left-color: var(--amber); }
.room-tab-name { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-tab-total { font-size: 11px; color: var(--amber); font-weight: 600; white-space: nowrap; }
.room-tab .btn-icon { flex-shrink: 0; width: 22px; height: 22px; font-size: 11px; }
.sidebar-add {
  padding: 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.editor-main {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
}
.editor-main-inner { padding: 24px 28px; flex: 1; }
.editor-main-inner .room-title {
  font-size: 18px; font-weight: 700; margin-bottom: 20px;
  display: flex; align-items: center; gap: 10px;
}
.editor-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; min-height: 300px; color: var(--muted); gap: 8px; text-align: center;
}
.editor-empty p { font-size: 14px; }

/* ─── SECTION TABLE ──────────────────────────────── */
.section-block { margin-bottom: 32px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
}
.section-subtotal { font-size: 13px; font-weight: 700; color: var(--amber); }

.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  padding: 7px 10px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.items-table th.col-num  { width: 36px; text-align: center; }
.items-table th.col-name { min-width: 160px; }
.items-table th.col-unit { width: 70px; }
.items-table th.col-qty  { width: 80px; }
.items-table th.col-price{ width: 100px; }
.items-table th.col-total{ width: 110px; text-align: right; }
.items-table th.col-del  { width: 36px; }

.items-table td {
  padding: 4px 4px;
  border-bottom: 1px solid rgba(48,54,61,.5);
  vertical-align: middle;
}
.items-table tr:last-child td { border-bottom: none; }
.items-table tr { transition: background .12s; }
.items-table tr:hover td { background: rgba(255,255,255,.025); }

.items-table .row-num {
  text-align: center; color: var(--muted); font-size: 11px;
}
.items-table .row-total {
  text-align: right; font-weight: 600; font-size: 13px; padding-right: 4px;
}
.items-table .row-total.nonzero { color: var(--amber); }

/* Inline editable cell */
.cell-edit {
  width: 100%; background: none; border: 1px solid transparent;
  color: var(--text); font-family: inherit; font-size: 13px;
  padding: 5px 8px; border-radius: 6px; transition: all .15s;
}
.cell-edit:hover { border-color: var(--border); }
.cell-edit:focus {
  outline: none; background: var(--bg); border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-glow);
}
.cell-edit.num { text-align: right; }

.add-row-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 6px 10px;
  background: none; border: 1px dashed var(--border);
  border-radius: 6px; color: var(--muted); font-family: inherit;
  font-size: 12px; cursor: pointer; transition: all .15s;
}
.add-row-btn:hover { border-color: var(--amber-dim); color: var(--amber); background: rgba(240,165,0,.06); }

/* ─── TOTAL BAR ──────────────────────────────────── */
.total-bar {
  padding: 14px 28px; background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.total-bar-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.total-bar-amount { font-size: 26px; font-weight: 800; color: var(--amber); letter-spacing: -1px; }
.total-bar-actions { display: flex; gap: 10px; }

/* ─── EDITOR HEADER ──────────────────────────────── */
.editor-header {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.editor-header-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 200px; }
.project-name-input {
  background: none; border: 1px solid transparent;
  color: var(--text); font-family: inherit; font-size: 16px; font-weight: 700;
  padding: 5px 8px; border-radius: 6px; min-width: 120px;
  transition: all .15s;
}
.project-name-input:hover { border-color: var(--border); }
.project-name-input:focus { outline: none; border-color: var(--amber); background: var(--bg); box-shadow: 0 0 0 3px var(--amber-glow); }
.project-addr-input {
  background: none; border: 1px solid transparent;
  color: var(--muted); font-family: inherit; font-size: 13px;
  padding: 4px 8px; border-radius: 6px; min-width: 100px;
  transition: all .15s;
}
.project-addr-input:hover { border-color: var(--border); }
.project-addr-input:focus { outline: none; border-color: var(--amber); background: var(--bg); color: var(--text); box-shadow: 0 0 0 3px var(--amber-glow); }

/* ─── SHARE VIEW ─────────────────────────────────── */
.share-header { padding: 16px 28px; background: var(--bg2); border-bottom: 1px solid var(--border); }
.share-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; padding: 3px 10px; border-radius: 20px;
  background: rgba(63,185,80,.12); border: 1px solid var(--green); color: var(--green);
  margin-bottom: 6px; font-weight: 600;
}
.share-project-name { font-size: 22px; font-weight: 800; }
.share-project-addr { color: var(--muted); font-size: 13px; margin-top: 2px; }
.share-main { padding: 28px; max-width: 860px; margin: 0 auto; }
.share-section { margin-bottom: 32px; }
.share-room-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.share-section-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; margin-top: 14px; }
.share-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-top: 2px solid var(--border); margin-top: 8px;
  font-size: 18px; font-weight: 800;
}
.share-total-row span:last-child { color: var(--amber); }

/* ─── MODAL ──────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  z-index: 500; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; max-width: 420px; width: 90%;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(.95) translateY(-8px); } to { opacity:1; transform:scale(1) translateY(0); } }
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* prompt modal */
.modal input[type="text"] {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: 14px;
  margin-bottom: 16px; transition: border-color .15s;
}
.modal input[type="text"]:focus { outline: none; border-color: var(--amber); }

/* ─── TOAST ──────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  max-width: 320px;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red);   }
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { to { opacity:0; transform:translateY(10px); } }

/* ─── NEW ROOM INPUT ─────────────────────────────── */
.new-room-form {
  padding: 10px 12px; background: var(--bg3);
  border-top: 1px solid var(--border); display: none;
}
.new-room-form.visible { display: block; }
.new-room-form input {
  width: 100%; padding: 7px 10px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: 13px; margin-bottom: 6px;
}
.new-room-form input:focus { outline: none; border-color: var(--amber); }
.new-room-form-btns { display: flex; gap: 6px; }

/* ─── ANIMATIONS ─────────────────────────────────── */
@keyframes rowIn {
  from { opacity:0; transform:translateY(-6px); }
  to   { opacity:1; transform:translateY(0); }
}
.row-new { animation: rowIn .2s ease; }

@keyframes cardIn {
  from { opacity:0; transform:translateY(12px); }
  to   { opacity:1; transform:translateY(0); }
}
.project-card { animation: cardIn .25s ease; }

/* ─── RESPONSIVE ─────────────────────────────────── */
@media (max-width: 700px) {
  .rooms-sidebar { width: 160px; }
  .editor-main-inner { padding: 14px; }
  .main { padding: 14px; }
  .total-bar-amount { font-size: 20px; }
  .items-table th.col-unit,
  .items-table td:nth-child(3) { display: none; }
}

/* ─── ROOM PICKER MODAL ──────────────────────────── */
.modal-room-picker {
  max-width: 600px;
  width: 96%;
  padding: 24px 24px 20px;
}
.modal-picker-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.modal-picker-head h3 { font-size: 17px; font-weight: 700; }
.picker-hint { font-size: 12px; color: var(--muted); margin-bottom: 14px; }

.room-type-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
@media (max-width: 500px) { .room-type-grid { grid-template-columns: repeat(3, 1fr); } }

.room-type-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 12px 6px;
  background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s;
  font-family: inherit; color: var(--text); text-align: center;
}
.room-type-btn:hover { border-color: var(--amber); background: rgba(240,165,0,.06); }
.room-type-btn.selected { border-color: var(--amber); background: rgba(240,165,0,.12); }
.room-type-icon {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(240,165,0,.1);
}
.room-type-icon svg { stroke: var(--amber); }
.room-type-name { font-size: 11px; font-weight: 600; line-height: 1.2; }
.room-type-meta { font-size: 10px; color: var(--muted); }

.picker-divider {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; color: var(--muted); font-size: 11px;
}
.picker-divider::before, .picker-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.picker-custom-row {
  display: flex; gap: 8px;
}
.picker-custom-row input {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: 13px;
  transition: border-color .15s;
}
.picker-custom-row input:focus { outline: none; border-color: var(--amber); }

/* Step 2: suggestions */
.suggest-room-name {
  font-size: 18px; font-weight: 800; color: var(--amber);
  margin-bottom: 4px;
}
.suggest-lists {
  max-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 18px;
}
.suggest-section-label {
  padding: 8px 14px 4px;
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.suggest-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: var(--bg3); }
.suggest-item input[type="checkbox"] {
  width: 15px; height: 15px; accent-color: var(--amber);
  cursor: pointer; flex-shrink: 0;
}
.suggest-item-info { flex: 1; }
.suggest-item-name { font-size: 13px; font-weight: 500; }
.suggest-item-sub  { font-size: 11px; color: var(--muted); }
.suggest-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ─── PRINT / PDF ────────────────────────────────── */
@media print {
  body { background: white !important; color: #1a1a2e !important; font-size: 11pt; }
  .view { display: none !important; }
  #print-doc { display: block !important; }
}
#print-doc { display: none; }
