/* ══════════════════════════════════════════
   FORM PANEL
══════════════════════════════════════════ */

/* Card title bar */
.card-title {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); display: flex; align-items: center; gap: 8px;
}
.card-title::before { content:''; width:16px; height:1px; background:var(--accent); display:inline-block; }

/* Fields */
.field { margin-bottom: 20px; }
label {
  display: block; font-size: 12px; color: var(--text-dim);
  margin-bottom: 8px; font-family: var(--font-mono); letter-spacing: .04em;
}
.input-wrap { position: relative; }

input[type="number"], input[type="text"], input[type="date"], select {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--rs); padding: 12px 16px; color: var(--text);
  font-family: var(--font-mono); font-size: 15px; outline: none;
  transition: border-color .2s, box-shadow .2s;
  -moz-appearance: textfield; appearance: none;
}
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,201,122,.1); }

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 d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px; cursor: pointer;
}

.unit {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); pointer-events: none;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Divider & section labels */
.divider { height: 1px; background: var(--border); }

.section-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 20px; cursor: pointer; user-select: none; transition: background .15s; gap: 8px;
}
.section-toggle:hover { background: rgba(232,201,122,.03); }
.section-label-text {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toggle-icon { font-size: 12px; color: var(--text-muted); flex-shrink: 0; transition: transform .2s; }

/* Tips */
.info-tip {
  background: rgba(232,201,122,.06); border: 1px solid rgba(232,201,122,.15);
  border-radius: var(--rs); padding: 12px; font-size: 12px;
  color: var(--text-dim); font-family: var(--font-mono); line-height: 1.6;
}
.grace-tip { background: rgba(245,158,11,.07) !important; border-color: rgba(245,158,11,.2) !important; }

/* Calc button */
.btn-calc {
  width: 100%; padding: 14px; background: var(--accent); color: #0d0f14;
  border: none; border-radius: var(--rs); font-family: var(--font-mono);
  font-size: 13px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase;
  cursor: pointer; transition: opacity .2s, transform .15s;
}
.btn-calc:hover { opacity: .9; transform: translateY(-1px); }
.btn-calc:active { transform: none; }

/* Principal formatted display */
.principal-wrap { position: relative; }
.principal-display {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 15px; color: var(--text); pointer-events: none;
}
input.has-display { color: transparent !important; caret-color: var(--text); }

/* ── Penalty table ── */
.penalty-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.penalty-table th {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .08em; padding: 6px 8px;
  border-bottom: 1px solid var(--border); font-weight: 400;
}
.penalty-table td { padding: 5px 4px; }
.penalty-cell { display: flex; align-items: center; gap: 6px; }
.penalty-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); white-space: nowrap; min-width: 46px; }

.penalty-year-input, .penalty-rate-input, .rs-input {
  width: 58px !important; padding: 6px 8px !important; font-size: 12px !important;
  text-align: center; background: var(--surface2) !important; border: 1px solid var(--border) !important;
  border-radius: var(--rxs) !important; color: var(--accent) !important;
  font-family: var(--font-mono) !important; -moz-appearance: textfield;
}
.penalty-year-input:focus, .penalty-rate-input:focus, .rs-input:focus {
  border-color: var(--accent) !important; box-shadow: 0 0 0 2px rgba(232,201,122,.15) !important; outline: none;
}
.penalty-year-input::-webkit-outer-spin-button, .penalty-year-input::-webkit-inner-spin-button,
.penalty-rate-input::-webkit-outer-spin-button, .penalty-rate-input::-webkit-inner-spin-button,
.rs-input::-webkit-outer-spin-button, .rs-input::-webkit-inner-spin-button { -webkit-appearance: none; }

.penalty-pct, .rs-pct { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }

.penalty-del {
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  color: var(--accent3); font-size: 11px; padding: 4px 7px; cursor: pointer; font-family: var(--font-mono);
}
.penalty-del:hover { background: rgba(248,113,113,.1); }
.penalty-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.penalty-empty { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); padding: 10px 0 4px; text-align: center; }

.penalty-btn {
  padding: 6px 12px; border-radius: var(--rxs); font-family: var(--font-mono);
  font-size: 11px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text-dim); transition: all .15s;
}
.penalty-btn:hover { border-color: var(--accent); color: var(--accent); }
.penalty-btn.add { border-color: rgba(110,231,183,.4); color: var(--accent2); }
.penalty-btn.add:hover { background: rgba(110,231,183,.08); }

/* ── Rate schedule ── */
.rs-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.rs-table colgroup col:nth-child(1) { width:42% }
.rs-table colgroup col:nth-child(2) { width:20% }
.rs-table colgroup col:nth-child(3) { width:20% }
.rs-table colgroup col:nth-child(4) { width:12% }
.rs-table colgroup col:nth-child(5) { width:6%  }
.rs-table th {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .07em; padding: 5px 4px;
  border-bottom: 1px solid var(--border); font-weight: 400;
}
.rs-table td { padding: 4px 3px; vertical-align: middle; overflow: hidden; }
.rs-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rs-field-wrap { display: flex; align-items: center; gap: 3px; min-width: 0; }
.rs-mini-label { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.rs-range-label { font-family: var(--font-mono); font-size: 10px; color: var(--accent2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-total { font-family: var(--font-mono); font-size: 11px; font-weight: 500; color: var(--accent2); white-space: nowrap; min-width: 48px; display: inline-block; }
.rs-tip {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); line-height: 1.6;
  background: rgba(110,231,183,.05); border: 1px solid rgba(110,231,183,.12);
  border-radius: var(--rxs); padding: 8px 10px; margin-bottom: 10px;
}
.rs-empty { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); padding: 10px 4px; text-align: center; }
.rs-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.rs-title { font-family: var(--font-mono); font-size: 11px; color: var(--accent2); text-transform: uppercase; letter-spacing: .08em; }
.rs-header-actions { display: flex; gap: 6px; }
#rateModeToggle.active { border-color: var(--accent2); color: var(--accent2); background: rgba(110,231,183,.07); }
.rs-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .field                { margin-bottom: 16px; }
  .row2                 { grid-template-columns: 1fr; gap: 14px; }
  input[type="number"], input[type="text"], input[type="date"], select {
    font-size: 16px; /* tránh iOS Safari tự zoom khi focus input */
    padding: 11px 14px;
  }
  .principal-display    { font-size: 16px; }
  .section-toggle        { padding: 11px 16px; }
  .collapsible-section .section-body { padding-left: 16px !important; padding-right: 16px !important; }
  .rs-table              { min-width: 480px; } /* cho phép cuộn ngang thay vì bóp méo */
  .penalty-table         { min-width: 340px; }
}
