/* ============================
Landing Cost Calculator
Mobile-first, max 480px
Primary: #1F4E79 Accent: #F4A300
============================ */

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

:root {
--primary: #1F4E79;
--primary-dark: #163a5f;
--primary-light: #2e6da4;
--accent: #F4A300;
--accent-dark: #d48f00;
--bg: #f0f4f8;
--card-bg: #ffffff;
--text: #1a2332;
--text-muted: #6b7a8d;
--border: #d1dbe6;
--success: #27ae60;
--danger: #e74c3c;
--input-h: 48px;
--radius: 12px;
--shadow: 0 2px 12px rgba(31,78,121,0.10);
}

html {
font-size: 16px;
-webkit-text-size-adjust: 100%;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
'Microsoft YaHei', sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
padding-bottom: 32px;
}

/* ---- Header ---- */
.app-header {
position: sticky;
top: 0;
z-index: 100;
background: var(--primary);
color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
height: 56px;
box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.app-header h1 {
font-size: 17px;
font-weight: 700;
letter-spacing: 0.01em;
line-height: 1.2;
}

.app-header h1 span {
display: block;
font-size: 11px;
font-weight: 400;
opacity: 0.8;
letter-spacing: 0.02em;
}

.lang-toggle {
background: rgba(255,255,255,0.15);
border: 1px solid rgba(255,255,255,0.3);
color: #fff;
border-radius: 20px;
padding: 5px 12px;
font-size: 13px;
cursor: pointer;
transition: background 0.2s;
white-space: nowrap;
}

.lang-toggle:hover, .lang-toggle:active {
background: rgba(255,255,255,0.25);
}

/* ---- Main container ---- */
.container {
max-width: 420px;
width: 100%;
margin: 0 auto;
padding: 12px 12px 0;
}

/* ---- Cards ---- */
.card {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 16px;
margin-bottom: 12px;
}

.card-title {
font-size: 14px;
font-weight: 700;
color: var(--primary);
border-bottom: 2px solid var(--primary);
padding-bottom: 8px;
margin-bottom: 14px;
display: flex;
align-items: center;
gap: 6px;
}

.card-title .icon {
width: 20px;
height: 20px;
background: var(--primary);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 11px;
font-weight: 700;
flex-shrink: 0;
}

/* ---- Form fields ---- */
.form-group {
margin-bottom: 12px;
}

.form-group:last-child {
margin-bottom: 0;
}

label {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 5px;
}

label .badge {
display: inline-block;
font-size: 10px;
font-weight: 600;
padding: 1px 6px;
border-radius: 10px;
margin-left: 5px;
vertical-align: middle;
}

label .badge-fta {
background: #e8f5e9;
color: #27ae60;
}

label .badge-mfn {
background: #fff3e0;
color: #e67e22;
}

input[type="text"],
input[type="number"],
select,
.search-input {
width: 100%;
height: var(--input-h);
border: 1.5px solid var(--border);
border-radius: 8px;
padding: 0 12px;
font-size: 15px;
color: var(--text);
background: #fff;
transition: border-color 0.2s, box-shadow 0.2s;
-webkit-appearance: none;
appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
outline: none;
border-color: var(--primary-light);
box-shadow: 0 0 0 3px rgba(31,78,121,0.12);
}

input[type="number"] {
-moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-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='%231F4E79' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 12px center;
padding-right: 32px;
}

/* ---- HS Code search ---- */
.hs-search-wrap {
position: relative;
}

.hs-search-wrap input {
padding-right: 40px;
}

.hs-clear-btn {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
color: var(--text-muted);
font-size: 18px;
cursor: pointer;
padding: 4px;
line-height: 1;
display: none;
}

.hs-dropdown {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
background: #fff;
border: 1.5px solid var(--primary-light);
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0,0,0,0.12);
z-index: 200;
max-height: 220px;
overflow-y: auto;
display: none;
}

.hs-dropdown.open {
display: block;
}

.hs-option {
padding: 10px 14px;
cursor: pointer;
border-bottom: 1px solid #f0f4f8;
transition: background 0.15s;
}

.hs-option:last-child {
border-bottom: none;
}

.hs-option:hover, .hs-option:active {
background: #eef4fb;
}

.hs-option .hs-code {
font-size: 12px;
color: var(--primary-light);
font-weight: 600;
}

.hs-option .hs-name {
font-size: 14px;
color: var(--text);
}

.hs-selected-info {
margin-top: 6px;
padding: 8px 10px;
background: #eef4fb;
border-radius: 6px;
font-size: 12px;
color: var(--primary);
display: none;
}

.hs-selected-info.show {
display: block;
}

.hs-selected-info .rate-row {
display: flex;
gap: 12px;
flex-wrap: wrap;
}

.hs-selected-info .rate-item {
display: flex;
align-items: center;
gap: 4px;
}

/* ---- Toggle buttons (FOB/CIF) ---- */
.toggle-group {
display: flex;
border-radius: 8px;
overflow: hidden;
border: 1.5px solid var(--primary);
}

.toggle-btn {
flex: 1;
height: var(--input-h);
background: #fff;
border: none;
color: var(--primary);
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s, color 0.2s;
}

.toggle-btn + .toggle-btn {
border-left: 1.5px solid var(--primary);
}

.toggle-btn.active {
background: var(--primary);
color: #fff;
}

/* ---- Container type / size toggles ---- */
.radio-group {
display: flex;
gap: 8px;
flex-wrap: wrap;
}

.radio-chip {
flex: 1;
min-width: 70px;
}

.radio-chip input[type="radio"] {
display: none;
}

.radio-chip label {
display: flex;
align-items: center;
justify-content: center;
height: 40px;
border: 1.5px solid var(--border);
border-radius: 8px;
font-size: 13px;
font-weight: 600;
color: var(--text-muted);
cursor: pointer;
transition: border-color 0.2s, background 0.2s, color 0.2s;
margin-bottom: 0;
user-select: none;
}

.radio-chip input:checked + label {
border-color: var(--primary);
background: var(--primary);
color: #fff;
}

/* ---- Input with unit suffix ---- */
.input-group {
display: flex;
align-items: center;
border: 1.5px solid var(--border);
border-radius: 8px;
overflow: hidden;
transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group:focus-within {
border-color: var(--primary-light);
box-shadow: 0 0 0 3px rgba(31,78,121,0.12);
}

.input-group input {
flex: 1;
height: var(--input-h);
border: none;
border-radius: 0;
padding: 0 12px;
font-size: 15px;
background: transparent;
}

.input-group input:focus {
outline: none;
box-shadow: none;
}

.input-suffix {
padding: 0 12px;
font-size: 13px;
font-weight: 600;
color: #fff;
background: var(--primary);
height: var(--input-h);
display: flex;
align-items: center;
white-space: nowrap;
}

/* ---- Freight auto-fill note ---- */
.auto-fill-note {
font-size: 11px;
color: var(--success);
margin-top: 4px;
display: none;
}

.auto-fill-note.show {
display: block;
}

/* ---- Calculate Button ---- */
.calc-btn {
width: 100%;
height: 54px;
background: var(--accent);
color: var(--primary-dark);
border: none;
border-radius: var(--radius);
font-size: 17px;
font-weight: 800;
letter-spacing: 0.02em;
cursor: pointer;
transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
box-shadow: 0 4px 14px rgba(244,163,0,0.35);
margin-bottom: 12px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}

.calc-btn:active {
transform: scale(0.98);
box-shadow: 0 2px 8px rgba(244,163,0,0.25);
}

.calc-btn:hover {
background: var(--accent-dark);
}

/* ---- Result Card ---- */
.result-card {
display: none;
}

.result-card.show {
display: block;
}

.result-highlight {
background: var(--primary);
border-radius: 10px;
padding: 16px;
text-align: center;
margin-bottom: 14px;
}

.result-highlight .label {
font-size: 12px;
color: rgba(255,255,255,0.75);
margin-bottom: 4px;
}

.result-highlight .amount {
font-size: 34px;
font-weight: 800;
color: var(--accent);
letter-spacing: -0.5px;
line-height: 1.1;
}

.result-highlight .amount-sub {
font-size: 13px;
color: rgba(255,255,255,0.65);
margin-top: 4px;
}

.result-rows {
display: flex;
flex-direction: column;
gap: 0;
}

.result-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 9px 0;
border-bottom: 1px solid var(--bg);
font-size: 14px;
}

.result-row:last-child {
border-bottom: none;
}

.result-row .r-label {
color: var(--text-muted);
display: flex;
align-items: center;
gap: 5px;
flex: 1;
}

.result-row .r-label .r-sub {
font-size: 11px;
color: #aab4be;
}

.result-row .r-value {
font-weight: 700;
color: var(--text);
text-align: right;
}

.result-row .r-value.tax {
color: var(--danger);
}

.result-row .r-value.fee {
color: var(--primary-light);
}

.result-row.total-row {
border-top: 2px solid var(--primary);
padding-top: 11px;
margin-top: 4px;
}

.result-row.total-row .r-label {
font-weight: 700;
color: var(--primary);
font-size: 15px;
}

.result-row.total-row .r-value {
font-size: 17px;
color: var(--primary);
}

.duty-tag {
font-size: 10px;
font-weight: 600;
padding: 2px 6px;
border-radius: 10px;
margin-left: 4px;
}

.duty-tag.fta {
background: #e8f5e9;
color: #27ae60;
}

.duty-tag.mfn {
background: #fff3e0;
color: #e67e22;
}

/* ---- History Panel ---- */
.history-panel {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
overflow: hidden;
margin-bottom: 12px;
}

.history-toggle {
width: 100%;
padding: 14px 16px;
background: none;
border: none;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
font-size: 14px;
font-weight: 700;
color: var(--primary);
text-align: left;
}

.history-toggle .chevron {
transition: transform 0.2s;
font-size: 12px;
color: var(--text-muted);
}

.history-toggle.open .chevron {
transform: rotate(180deg);
}

.history-list {
display: none;
padding: 0 12px 12px;
}

.history-list.open {
display: block;
}

.history-empty {
text-align: center;
color: var(--text-muted);
font-size: 13px;
padding: 16px 0;
}

.history-item {
border: 1px solid var(--border);
border-radius: 8px;
padding: 10px 12px;
margin-bottom: 8px;
cursor: pointer;
transition: border-color 0.2s, background 0.2s;
}

.history-item:hover, .history-item:active {
border-color: var(--primary-light);
background: #eef4fb;
}

.history-item:last-child {
margin-bottom: 0;
}

.history-item .hi-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 4px;
}

.history-item .hi-title {
font-size: 13px;
font-weight: 600;
color: var(--text);
}

.history-item .hi-total {
font-size: 14px;
font-weight: 700;
color: var(--primary);
}

.history-item .hi-meta {
font-size: 11px;
color: var(--text-muted);
display: flex;
gap: 8px;
flex-wrap: wrap;
}

/* ---- Error / Info messages ---- */
.error-msg {
background: #fdecea;
border-left: 3px solid var(--danger);
border-radius: 6px;
padding: 10px 12px;
font-size: 13px;
color: var(--danger);
margin-top: 8px;
display: none;
}

.error-msg.show {
display: block;
}

.info-row {
background: #eef4fb;
border-radius: 6px;
padding: 8px 12px;
font-size: 12px;
color: var(--primary-light);
margin-top: 8px;
}

/* ---- Loading spinner ---- */
.spinner {
display: inline-block;
width: 18px;
height: 18px;
border: 2px solid rgba(31,78,121,0.3);
border-top-color: var(--primary);
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

@keyframes spin {
to { transform: rotate(360deg); }
}

/* ---- Responsive tweaks ---- */
@media (max-width: 360px) {
.app-header h1 {
font-size: 15px;
}

.radio-group {
gap: 6px;
}

.result-highlight .amount {
font-size: 28px;
}
}

@media (min-width: 480px) {
.container {
padding: 16px 16px 0;
}

.card {
padding: 20px;
}
}

/* ---- Wide screen: keep narrow mobile layout ---- */
@media (min-width: 600px) {
.app-header {
padding: 0 calc(50% - 210px);
}
.container {
max-width: 420px;
padding: 16px 0 0;
}
}