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

html { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #222;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: 200px;
  min-width: 200px;
  background: #1e2a3a;
  color: #cdd5e0;
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid #2d3f55;
}

#sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  letter-spacing: 0.5px;
}

#table-list {
  list-style: none;
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

#table-list li {
  padding: 10px 20px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
  font-size: 13.5px;
}

#table-list li:hover { background: #2d3f55; }
#table-list li.active { background: #2563eb; color: #fff; font-weight: 600; }

#db-status {
  padding: 16px;
  border-top: 1px solid #2d3f55;
  font-size: 12px;
}

#db-name {
  display: block;
  margin-bottom: 8px;
  color: #8a9bb0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main content ── */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  gap: 12px;
}

#table-title {
  font-size: 20px;
  font-weight: 700;
  color: #111;
  white-space: nowrap;
}

#toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

#search-box {
  padding: 7px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  width: 220px;
  outline: none;
}
#search-box:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

#no-db-message {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #6b7280;
  font-size: 15px;
}

#table-container {
  flex: 1;
  overflow: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

th {
  background: #f9fafb;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  padding: 9px 14px;
  border-bottom: 1px solid #f0f0f0;
  color: #374151;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:hover td { background: #f0f7ff; }
tr:last-child td { border-bottom: none; }

td.actions {
  white-space: nowrap;
  width: 1%;
  padding: 6px 10px;
}

/* ── Buttons ── */
button { cursor: pointer; border: none; border-radius: 6px; font-size: 13px; font-family: inherit; transition: background 0.15s; }

.btn-primary { background: #2563eb; color: #fff; padding: 8px 16px; font-weight: 600; }
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary { background: #e5e7eb; color: #374151; padding: 8px 16px; }
.btn-secondary:hover { background: #d1d5db; }

.btn-danger { background: #dc2626; color: #fff; padding: 8px 16px; }
.btn-danger:hover { background: #b91c1c; }

.btn-icon { background: none; padding: 4px 8px; font-size: 15px; border-radius: 4px; }
.btn-icon.edit { color: #2563eb; }
.btn-icon.edit:hover { background: #eff6ff; }
.btn-icon.delete { color: #dc2626; }
.btn-icon.delete:hover { background: #fef2f2; }

#open-btn { width: 100%; background: #2563eb; color: #fff; padding: 8px 12px; font-size: 12px; font-weight: 600; border-radius: 6px; }
#open-btn:hover { background: #1d4ed8; }

/* ── Modal ── */
#modal-overlay, #confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

#modal {
  background: #fff;
  border-radius: 10px;
  padding: 28px;
  width: 520px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

#modal-title { font-size: 18px; font-weight: 700; }

#modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: 55vh;
  padding-right: 4px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: #374151; text-transform: uppercase; letter-spacing: 0.4px; }
.form-group input, .form-group textarea, .form-group select {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
}
.form-group input:focus, .form-group textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.12); }
.form-group textarea { resize: vertical; min-height: 60px; }

#modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }

#confirm-dialog {
  background: #fff;
  border-radius: 10px;
  padding: 28px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

#confirm-message { font-size: 15px; line-height: 1.5; }
#confirm-buttons { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e2a3a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
}
#toast.show { opacity: 1; }
#toast.error { background: #dc2626; }

/* ── Webapp-specific additions ── */

#save-btn {
  width: 100%;
  background: #16a34a;
  color: #fff;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  margin-top: 8px;
}
#save-btn:hover { background: #15803d; }
#save-btn:disabled { background: #4b5563; cursor: not-allowed; }

#fallback-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  padding: 8px 16px;
  text-align: center;
  z-index: 300;
}
#fallback-banner.show { display: block; }
#fallback-banner a { color: #92400e; font-weight: 700; text-decoration: underline; cursor: pointer; }

#install-banner {
  display: none;
  position: fixed;
  bottom: 80px; right: 24px;
  background: #1e2a3a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  gap: 10px;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  z-index: 250;
  max-width: 280px;
}
#install-banner.show { display: flex; }
#install-banner button { background: #2563eb; color: #fff; padding: 6px 12px; font-size: 12px; border-radius: 6px; white-space: nowrap; }
#install-banner .dismiss { background: none; color: #8a9bb0; padding: 4px 6px; font-size: 16px; }

#drop-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(37,99,235,.18);
  border: 3px dashed #2563eb;
  z-index: 400;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #2563eb;
  pointer-events: none;
}
#drop-overlay.show { display: flex; }
