/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --c-bg: #f0f2f5;
    --c-surface: #ffffff;
    --c-primary: #2563eb;
    --c-primary-hover: #1d4ed8;
    --c-secondary: #475569;
    --c-secondary-hover: #334155;
    --c-accent: #059669;
    --c-accent-hover: #047857;
    --c-eme: #3b82f6;
    --c-otd: #8b5cf6;
    --c-mov: #f59e0b;
    --c-rpb: #ef4444;
    --c-border: #e2e8f0;
    --c-text: #1e293b;
    --c-text-secondary: #64748b;
    --c-notice-bg: #eff6ff;
    --c-notice-border: #bfdbfe;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.06);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff;
    padding: 1.5rem 1rem;
}

.header__inner {
    max-width: 1200px;
    margin: 0 auto;
}

.header__title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header__subtitle {
    font-size: 0.875rem;
    opacity: 0.85;
    margin-top: 0.25rem;
}

.main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.footer {
    text-align: center;
    padding: 1rem;
    color: var(--c-text-secondary);
    font-size: 0.8rem;
    border-top: 1px solid var(--c-border);
}

/* ===== Form Card ===== */
.form-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-section__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--c-text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
}

/* ===== Grid ===== */
.form-grid {
    display: grid;
    gap: 1rem;
}

.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
.form-grid--1 { grid-template-columns: 1fr; max-width: 280px; }

.objects-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

/* ===== Field ===== */
.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--c-text);
    font-family: 'Courier New', monospace;
}

.field__input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.field__input:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field__input:disabled,
.field__input[readonly] {
    background: #f8fafc;
    color: var(--c-text-secondary);
    cursor: not-allowed;
}

.field__input--computed {
    background: #f0fdf4;
    border-color: #86efac;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.field__hint {
    font-size: 0.7rem;
    color: var(--c-text-secondary);
}

/* ===== Object Cards ===== */
.object-card {
    background: var(--c-surface);
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    border-top: 3px solid var(--c-border);
}

.object-card--eme { border-top-color: var(--c-eme); }
.object-card--otd { border-top-color: var(--c-otd); }
.object-card--mov { border-top-color: var(--c-mov); }
.object-card--rpb { border-top-color: var(--c-rpb); }

.object-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.object-card__name {
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.object-card--disabled {
    opacity: 0.45;
    border-top-color: var(--c-border) !important;
}

.object-card--disabled .object-card__fields {
    pointer-events: none;
}

/* ===== Toggle Switch ===== */
.toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle__slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 20px;
    transition: background 0.2s;
}

.toggle__slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle input:checked + .toggle__slider { background: var(--c-primary); }
.toggle input:checked + .toggle__slider::before { transform: translateX(16px); }

.object-card--eme .object-card__name { color: var(--c-eme); }
.object-card--otd .object-card__name { color: var(--c-otd); }
.object-card--mov .object-card__name { color: var(--c-mov); }
.object-card--rpb .object-card__name { color: var(--c-rpb); }

.object-card__fields {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ===== Buttons ===== */
.actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    flex: 1;
    justify-content: center;
    min-width: 140px;
}

.btn:active { transform: scale(0.98); }

.btn__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn--primary {
    background: var(--c-primary);
    color: #fff;
}
.btn--primary:hover { background: var(--c-primary-hover); box-shadow: var(--shadow); }

.btn--secondary {
    background: var(--c-secondary);
    color: #fff;
}
.btn--secondary:hover { background: var(--c-secondary-hover); box-shadow: var(--shadow); }

.btn--accent {
    background: var(--c-accent);
    color: #fff;
}
.btn--accent:hover { background: var(--c-accent-hover); box-shadow: var(--shadow); }

/* ===== Notice ===== */
.notice {
    display: flex;
    gap: 0.75rem;
    background: var(--c-notice-bg);
    border: 1px solid var(--c-notice-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.notice__icon svg {
    width: 22px;
    height: 22px;
    color: var(--c-primary);
    flex-shrink: 0;
}

.notice__content strong {
    display: block;
    margin-bottom: 0.25rem;
}

.notice__content p {
    font-size: 0.85rem;
    color: var(--c-text-secondary);
}

.notice__details {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    font-family: 'Courier New', monospace;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.notice__detail-item {
    background: #fff;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
}

/* ===== Result Card ===== */
.result-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.result-card__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--c-text-secondary);
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.result-item {
    background: var(--c-bg);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    border-top: 3px solid var(--c-border);
}

.result-item--eme { border-top-color: var(--c-eme); }
.result-item--otd { border-top-color: var(--c-otd); }
.result-item--mov { border-top-color: var(--c-mov); }
.result-item--rpb { border-top-color: var(--c-rpb); }

.result-item__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--c-text-secondary);
    margin-bottom: 0.25rem;
}

.result-item__value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.result-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid var(--c-border);
    font-size: 1.1rem;
    font-weight: 700;
}

/* ===== Table ===== */
.table-container {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.table-container__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--c-text-secondary);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    white-space: nowrap;
}

.data-table th {
    background: #1e3a5f;
    color: #fff;
    font-weight: 600;
    padding: 0.75rem 1rem;
    text-align: right;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th:first-child { text-align: left; }

.data-table td {
    padding: 0.5rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--c-border);
    font-family: 'Courier New', monospace;
}

.data-table td:first-child { text-align: left; font-weight: 600; }
.data-table td:last-child { text-align: center; }

.data-table tbody tr:hover { background: #f1f5f9; }
.data-table tbody tr:nth-child(even) { background: #f8fafc; }
.data-table tbody tr:nth-child(even):hover { background: #f1f5f9; }

.data-table .row-highlight { background: #fef3c7 !important; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font);
}

.badge--yes { background: #fee2e2; color: #dc2626; }
.badge--no { background: #dcfce7; color: #16a34a; }

/* ===== Loading ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--c-text-secondary);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .objects-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    html { font-size: 14px; }

    .header { padding: 1rem; }
    .header__title { font-size: 1.25rem; }

    .form-grid--3 { grid-template-columns: 1fr; }
    .objects-grid { grid-template-columns: 1fr; }
    .result-grid { grid-template-columns: 1fr; }

    .actions {
        flex-direction: column;
    }
    .btn { width: 100%; }

    .main { padding: 1rem 0.5rem; }
    .form-card { padding: 1rem; }

    .table-wrapper { max-height: 70vh; overflow-y: auto; }
}

/* ===== Scrollbar ===== */
.table-wrapper::-webkit-scrollbar { height: 8px; width: 8px; }
.table-wrapper::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
.table-wrapper::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.table-wrapper::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
