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

body {
    font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    background: #f0f2f5;
    color: #1f2328;
    min-height: 100vh;
}

.container {
    max-width: 820px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
    text-align: center;
    margin-bottom: 32px;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #1f2328;
    letter-spacing: -0.5px;
}

.subtitle {
    color: #57606a;
    margin-top: 6px;
    font-size: 0.95rem;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 28px;
    margin-bottom: 20px;
}

/* ─── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 20px;
    font-size: 0.93rem;
}
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* ─── Form ─────────────────────────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #374151;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.badge-dev  { background: #dbeafe; color: #1d4ed8; }
.badge-prod { background: #fce7f3; color: #be185d; }

/* File input */
.file-input-wrapper {
    position: relative;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    background: #f9fafb;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.file-input-wrapper:hover,
.file-input-wrapper.has-file {
    border-color: #3b82d4;
    background: #eff6ff;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.file-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 28px 16px;
    color: #6b7280;
    font-size: 0.88rem;
    text-align: center;
    pointer-events: none;
}

.file-placeholder svg { color: #9ca3af; }

.file-input-wrapper.has-file .file-placeholder { color: #1d4ed8; font-weight: 600; }
.file-input-wrapper.has-file .file-placeholder svg { color: #3b82d4; }

/* Submit button */
.form-footer {
    margin-top: 24px;
    display: flex;
    justify-content: center;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #3b82d4;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 28px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: #2563eb; }

/* ─── Info box ─────────────────────────────────────────────────────────────── */
.info-box {
    background: #f7f8fa;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 20px;
}
.info-box h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 10px; color: #374151; }
.info-box ol { padding-left: 20px; color: #57606a; font-size: 0.9rem; }
.info-box ol li { margin-bottom: 4px; }
.info-box code { background: #e5e7eb; border-radius: 4px; padding: 1px 5px; font-size: 0.85rem; }
.info-note { margin-top: 12px; font-size: 0.85rem; color: #57606a; }

/* ─── Stats bar ────────────────────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.stat {
    flex: 1;
    min-width: 100px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    text-align: center;
}
.stat-highlight {
    border-color: #bfdbfe;
    background: #eff6ff;
}
.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: #1f2328;
    line-height: 1;
}
.stat-highlight .stat-value { color: #1d4ed8; }
.stat-label {
    display: block;
    font-size: 0.78rem;
    color: #6b7280;
    margin-top: 4px;
}

/* ─── Diff list ────────────────────────────────────────────────────────────── */
.section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1f2328;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.diff-list { display: flex; flex-direction: column; gap: 10px; }

.diff-item {
    border-radius: 7px;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
}
.diff-new   { background: #f0fdf4; border-color: #bbf7d0; }
.diff-alter { background: #fafafa; }

.diff-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-right: 8px;
    vertical-align: middle;
}
.badge-new   { background: #dcfce7; color: #166534; }
.badge-alter { background: #dbeafe; color: #1d4ed8; }

.diff-item code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.88rem;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 4px;
}

.diff-table-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.diff-count {
    margin-left: auto;
    font-size: 0.78rem;
    color: #6b7280;
}

.diff-ops {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.diff-ops li {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.87rem;
}

.op-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}
.op-add_column     { background: #dcfce7; color: #166534; }
.op-modify_column  { background: #fef9c3; color: #854d0e; }
.op-drop_column    { background: #fee2e2; color: #991b1b; }
.op-add_index      { background: #e0e7ff; color: #3730a3; }
.op-drop_index     { background: #fce7f3; color: #9d174d; }
.op-add_primary_key { background: #d1fae5; color: #065f46; }
.op-drop_primary_key { background: #fecaca; color: #991b1b; }

.op-def {
    color: #57606a;
    font-size: 0.8rem;
    font-family: "SFMono-Regular", Consolas, monospace;
    word-break: break-all;
}

/* ─── SQL Output ───────────────────────────────────────────────────────────── */
.script-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 0;
}
.script-actions { display: flex; gap: 10px; }

.btn-copy, .btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #374151;
    transition: background 0.15s, border-color 0.15s;
}
.btn-copy:hover, .btn-download:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}
.btn-download { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.btn-download:hover { background: #dbeafe; }

.btn-apply {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #b91c1c;
    transition: background 0.15s, border-color 0.15s;
}
.btn-apply:hover:not(:disabled) {
    background: #fee2e2;
    border-color: #fca5a5;
}
.btn-apply:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─── Apply-to-prod modal & result ─────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal {
    background: #ffffff;
    border-radius: 10px;
    max-width: 460px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}
.modal-header h3 {
    font-size: 1.1rem;
    color: #b91c1c;
    margin-bottom: 12px;
}
.modal-body {
    font-size: 0.92rem;
    color: #374151;
    margin-bottom: 20px;
}
.modal-body p { margin-bottom: 10px; }
.modal-target { text-align: center; margin: 14px 0; }
.modal-warning {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.88rem;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.apply-result {
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1.5;
}
.apply-result-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}
.apply-result-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.sql-output {
    margin-top: 16px;
    background: #0d1117;
    color: #c9d1d9;
    border-radius: 8px;
    padding: 20px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    overflow-x: auto;
    white-space: pre;
    max-height: 520px;
    overflow-y: auto;
}

/* ─── Back button ──────────────────────────────────────────────────────────── */
.card-actions { margin-bottom: 20px; }
.btn-back {
    display: inline-block;
    padding: 9px 20px;
    border-radius: 7px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-back:hover { background: #f3f4f6; }

/* ─── Footer ───────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    border-top: 1px solid #e5e7eb;
    padding-top: 16px;
    font-size: 0.8rem;
    color: #9ca3af;
}

/* ─── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    background: #f0f2f5;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 5px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 16px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #57606a;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: #e9ebee; color: #1f2328; }
.tab-btn.active {
    background: #ffffff;
    color: #1f2328;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Connection form ──────────────────────────────────────────────────────── */
.conn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
}
@media (max-width: 640px) {
    .conn-grid { grid-template-columns: 1fr; }
}

.conn-card { padding: 22px 24px; }

.conn-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    color: #1f2328;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"] {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #1f2328;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus {
    outline: none;
    border-color: #3b82d4;
    box-shadow: 0 0 0 3px rgba(59,130,212,0.12);
}
.form-group input::placeholder { color: #9ca3af; }

/* Password with toggle */
.pass-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.pass-wrapper input {
    padding-right: 38px !important;
}
.toggle-pass {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 2px;
    line-height: 1;
    display: flex;
    align-items: center;
}
.toggle-pass:hover { color: #57606a; }

/* Save checkbox */
.conn-options {
    margin-bottom: 4px;
    padding: 0 4px;
}
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: #57606a;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #3b82d4;
}

/* Connection labels in result header */
.conn-label {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
}
.conn-label.badge-dev  { background: #dbeafe; color: #1d4ed8; }
.conn-label.badge-prod { background: #fce7f3; color: #be185d; }

/* info-box list style (for the connect tab) */
.info-box ul {
    padding-left: 20px;
    color: #57606a;
    font-size: 0.9rem;
}
.info-box ul li { margin-bottom: 4px; }

/* ─── Table-by-table diff blocks ───────────────────────────────────────────── */
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 0 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.section-heading h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1f2328;
}
.expand-controls { display: flex; align-items: center; gap: 8px; }
.btn-text {
    background: none;
    border: none;
    color: #3b82d4;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 0;
}
.btn-text:hover { text-decoration: underline; }
.sep { color: #d1d5db; font-size: 0.85rem; }

/* Each table block */
.table-block {
    border: 1px solid #e5e7eb;
    border-radius: 9px;
    margin-bottom: 10px;
    overflow: hidden;
    background: #fff;
}
.table-block-new   { border-color: #bbf7d0; }
.table-block-alter { border-color: #bfdbfe; }
.table-block-pk    { border-color: #fcd34d; }

/* Header (clickable) */
.table-block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    cursor: pointer;
    user-select: none;
    background: #f7f8fa;
    transition: background 0.12s;
}
.table-block-new   .table-block-header { background: #f0fdf4; }
.table-block-alter .table-block-header { background: #eff6ff; }
.table-block-pk    .table-block-header { background: #fefce8; }
.table-block-header:hover { filter: brightness(0.97); }

.tbl-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    white-space: nowrap;
}
.tbl-new   { background: #dcfce7; color: #166534; }
.tbl-alter { background: #dbeafe; color: #1d4ed8; }
.tbl-pk    { background: #fef3c7; color: #92400e; }

.tbl-name {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.92rem;
    font-weight: 700;
    color: #1f2328;
}
.tbl-ops-count {
    margin-left: auto;
    font-size: 0.78rem;
    color: #6b7280;
}
.tbl-chevron {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-left: 6px;
    transition: transform 0.15s;
}

/* Collapsed state */
.table-block.collapsed .table-block-body { display: none; }

/* Inner diff table */
.table-block-body { padding: 0; }
.diff-table-wrapper { overflow-x: auto; }

.diff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
}
.diff-table th {
    background: #f1f5f9;
    padding: 8px 12px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.diff-table th:nth-child(1) { width: 160px; }
.diff-table th:nth-child(4) { width: 130px; }

.diff-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: top;
    color: #374151;
}
.diff-table tr:last-child td { border-bottom: none; }
.diff-table td code {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.82rem;
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
}

/* Definition cells */
.def-cell {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.79rem;
    color: #374151;
    word-break: break-all;
    max-width: 260px;
}
.empty-cell { color: #9ca3af; font-style: italic; }

/* Row colour coding */
.row-add      { background: #f0fdf4; }
.row-modify   { background: #fefce8; }
.row-drop     { background: #fef2f2; }
.row-pk-add   { background: #ecfdf5; }
.row-pk-drop  { background: #fef2f2; }
.row-idx-add  { background: #f5f3ff; }
.row-idx-drop { background: #fff7ed; }

/* Op badges (used inside diff-table) */
.op-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 0.68rem;
    font-weight: 800;
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.op-add      { background: #dcfce7; color: #166534; }
.op-modify   { background: #fef9c3; color: #854d0e; }
.op-drop     { background: #fee2e2; color: #991b1b; }
.op-pk-add   { background: #d1fae5; color: #065f46; }
.op-pk-drop  { background: #fee2e2; color: #991b1b; }
.op-idx-add  { background: #ede9fe; color: #5b21b6; }
.op-idx-drop { background: #ffedd5; color: #9a3412; }
