:root {
  --bg0: #f4f6f9;
  --bg1: #e8eef6;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-hover: #0d9488;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --danger: #be123c;
  --mass-bg: #ecfeff;
  --mass-border: #a5f3fc;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --control-height: 38px;
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(45, 212, 191, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.14), transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 18px 10px;
  gap: 12px;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 2px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background:
    linear-gradient(145deg, #14b8a6 0%, #0f766e 55%, #0e7490 100%);
  box-shadow: var(--shadow);
}

.brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.1;
}

.subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  flex: 1;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 10px;
  align-items: center;
  font-weight: 500;
  color: var(--text-secondary);
}

.field-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.field-row > input,
.field-row > select {
  width: 100%;
  min-width: 0;
}

/* Shared form controls — include password so login matches username */
select,
input[type="number"],
input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
button {
  font-family: var(--font);
  font-size: 13px;
}

select,
input[type="number"],
input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: var(--control-height);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1.4 1.4 6 6l4.6-4.6L12 2.8 6 8.8 0 2.8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

select:focus,
input[type="number"]:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="email"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

button {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  min-height: var(--control-height);
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: var(--surface-muted);
  border-color: #94a3b8;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: transparent;
  padding: 8px 18px;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

button.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
}

button.btn-muted {
  color: var(--text-secondary);
  font-weight: 500;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1.1fr 0.95fr 1.1fr;
  gap: 12px;
  min-height: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 14px;
  gap: 10px;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.panel-header-sub {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.panel-hint {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.table-wrap {
  flex: 1;
  overflow: auto;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 280px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}

td input,
td select {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  min-height: 30px;
  border-radius: 6px;
  padding: 4px 6px;
  font-family: var(--mono);
  font-size: 12px;
  appearance: none;
  -webkit-appearance: none;
  background-image: none;
}

td input:focus,
td select:focus {
  border-color: var(--accent);
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

td input[readonly] {
  color: var(--accent);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-remove {
  min-height: 30px;
  min-width: 30px;
  padding: 0;
  line-height: 1;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 16px;
}

.btn-remove:hover {
  color: var(--danger);
  border-color: #fecdd3;
  background: #fff1f2;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.conditions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conditions .cond.hidden {
  display: none;
}

.props {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  min-width: 0;
}

.prop {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  min-width: 0;
}

.prop span {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.prop b {
  font-weight: 500;
  color: var(--text);
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.extra {
  margin: 0;
  flex: 1;
  min-height: 88px;
  overflow: auto;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.keq-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keq-panel .field {
  min-width: 0;
}

.hidden {
  display: none !important;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
}

.statusbar #statusText {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

body.mass-units .reactants-col .table-wrap,
body.mass-units .products-col .table-wrap {
  background: var(--mass-bg);
  border-color: var(--mass-border);
}

body.mass-units #statusUnits {
  background: #cffafe;
  color: #0e7490;
}

/* —— Login —— */
body.login-page {
  overflow: auto;
}

.login-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 18px;
}

.login-panel {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand {
  margin-bottom: 6px;
}

.login-panel .field {
  min-width: 0;
  width: 100%;
}

.login-panel input {
  width: 100%;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
}

.user-chip {
  background: var(--surface-muted);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  font-size: 11px;
  margin-right: 4px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Responsive —— */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
  }

  .products-col {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  html, body {
    overflow: auto;
  }

  #app {
    height: auto;
    min-height: 100%;
    padding: 14px 14px 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .products-col {
    grid-column: auto;
  }

  .titlebar {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .field {
    min-width: 160px;
  }

  .table-wrap {
    min-height: 180px;
  }

  .conditions-col .extra {
    min-height: 120px;
  }
}

@media (max-width: 640px) {
  #app {
    padding: 12px 10px 10px;
    gap: 10px;
  }

  .brand {
    font-size: 20px;
  }

  .toolbar {
    padding: 12px;
  }

  .field {
    min-width: 0;
    flex: 1 1 100%;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .props {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel {
    padding: 12px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1 1 auto;
  }

  .statusbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .login-shell {
    padding: 20px 14px;
    align-items: flex-start;
  }

  .login-panel {
    padding: 22px 18px 20px;
  }

  table {
    min-width: 260px;
  }

  th, td {
    padding: 6px;
  }
}
