/* ==========================================================================
   CustomerFlow Survey – Stylesheet
   Variables --primary-color / --secondary-color are injected from branding.
   ========================================================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #1e293b;
    background: #f1f5f9;
    min-height: 100vh;
}

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

.site-header {
    background: var(--primary-color, #1e3a5f);
    color: #fff;
    padding: 0.875rem 2rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 960px;
    margin: 0 auto;
}

.site-logo {
    max-height: 44px;
    width: auto;
}

.company-name {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.site-main {
    flex: 1;
    padding: 2.5rem 1rem;
}

.site-footer {
    text-align: center;
    padding: 1.25rem;
    color: #94a3b8;
    font-size: 0.78rem;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

/* --- Containers --- */
.survey-container,
.admin-container {
    max-width: 860px;
    margin: 0 auto;
    background: #fff;
    border-radius: 6px;
    padding: 2.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.04);
}

.login-container {
    max-width: 440px;
}

.install-container {
    max-width: 620px;
}

/* --- Install page --- */
.install-intro {
    font-size: 1.05rem;
    color: #374151;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.install-intro-en {
    color: #6b7280;
    font-size: 0.95rem;
}

/* Steps */
.install-step {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 0;
    margin-bottom: 1.75rem;
    overflow: hidden;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 4px;
    background: var(--primary-color, #1e3a5f);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.step-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
    line-height: 1.3;
}

.step-subtitle {
    font-size: 0.85rem;
    color: #94a3b8;
    margin: 0.125rem 0 0;
}

.step-body {
    padding: 1.5rem;
}

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

/* Driver selection cards */
.driver-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.driver-card {
    position: relative;
    cursor: pointer;
}

.driver-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.driver-card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 1.25rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 4px;
    text-align: center;
    transition: border-color .2s, box-shadow .2s, background .2s;
    background: #fff;
}

.driver-card--selected .driver-card-inner {
    border-color: var(--primary-color, #1e3a5f);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, .1);
    background: #f0f4f8;
}

.driver-card:not(.driver-card--disabled):hover .driver-card-inner {
    border-color: #94a3b8;
}

.driver-card--disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.driver-card-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.driver-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
}

.driver-card-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
}

.badge--ok {
    background: #f0fdf4;
    color: #15803d;
}

.badge--no {
    background: #fef2f2;
    color: #b91c1c;
}

.driver-card-desc {
    font-size: 0.8rem;
    color: #6b7280;
    line-height: 1.3;
}

/* MySQL fields */
.mysql-fields {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid #e2e8f0;
}

.mysql-fields-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 1rem;
}

/* Submit area */
.install-submit {
    text-align: center;
    padding: 1rem 0 0.5rem;
}

/* Helpers */
.form-hint {
    font-size: 0.85rem;
    color: #6b7280;
    margin-top: 0.375rem;
    line-height: 1.4;
}

/* --- Typography --- */
h1 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    color: #0f172a;
    font-weight: 700;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: #1e293b;
    font-weight: 600;
}

.page-subtitle {
    color: #64748b;
    font-size: 0.95rem;
    margin-bottom: 1.75rem;
}

/* --- Survey header area --- */
.survey-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.survey-header h1 {
    margin-bottom: 0.75rem;
}

.survey-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin-bottom: 1rem;
}

.survey-meta-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.9rem;
    color: #6b7280;
}

.survey-meta-item .meta-icon {
    font-size: 1rem;
    opacity: 0.5;
}

.survey-meta-item strong {
    color: #334155;
    font-weight: 600;
}

.survey-context {
    color: #64748b;
    margin-bottom: 0.5rem;
}

.welcome-text {
    font-size: 1rem;
    margin: 1.25rem 0 0;
    padding: 0.875rem 1.25rem;
    background: #f8fafc;
    border-left: 3px solid var(--primary-color, #1e3a5f);
    border-radius: 0 4px 4px 0;
    color: #334155;
    line-height: 1.4;
}

.rating-help {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: #94a3b8;
    font-size: 0.85rem;
    margin-bottom: 1.75rem;
    font-style: normal;
    background: #f8fafc;
    padding: 0.5rem 0.875rem;
    border-radius: 4px;
    font-weight: 500;
}

/* --- Alerts --- */
.alert {
    padding: 0.875rem 1.125rem;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    font-weight: 500;
    font-size: 0.925rem;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    line-height: 1.5;
}

.alert::before {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-left: 3px solid #dc2626;
}

.alert-error::before {
    content: "\26A0";
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border-left: 3px solid #16a34a;
}

.alert-success::before {
    content: "\2713";
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: #334155;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    transition: border-color .2s, box-shadow .2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color, #1e3a5f);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, .1);
    background: #fff;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: #94a3b8;
}

textarea {
    resize: vertical;
}

.question-group textarea {
    width: 100%;
    min-height: 140px;
    padding: 0.625rem 0.875rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    transition: border-color .2s, box-shadow .2s;
}

.question-group textarea:focus {
    outline: none;
    border-color: var(--primary-color, #1e3a5f);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, .1);
    background: #fff;
}

.question-group textarea::placeholder {
    color: #94a3b8;
}

.char-counter {
    text-align: right;
    font-size: 0.8rem;
    color: #9ca3af;
    margin-top: 0.375rem;
}

.form-actions {
    margin-top: 1.75rem;
}

/* Card-style form sections */
.form-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1.75rem;
}

.form-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.form-card-header h2 {
    margin: 0;
    font-size: 0.95rem;
}

.form-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: #475569;
    flex-shrink: 0;
}

.form-card-icon svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
}

.form-card-body {
    padding: 1.5rem;
}

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

.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e2e8f0;
}

.form-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, box-shadow .15s;
    line-height: 1.4;
}

.btn:active {
    transform: none;
}

.btn-primary {
    background: var(--primary-color, #1e3a5f);
    color: #fff;
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--secondary-color, #152a45);
}

.btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
    box-shadow: none;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    box-shadow: none;
}

.btn-danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 3px;
}

.btn-lg {
    padding: 0.75rem 2rem;
    font-size: 1rem;
}

/* --- Star Rating --- */
.question-group {
    margin-bottom: 0.75rem;
    padding: 1.125rem 1.375rem;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    transition: border-color .2s;
}

.question-group:hover {
    border-color: #cbd5e1;
}

.question-label {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #1e293b;
    font-size: 0.925rem;
}

.question-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 3px;
    background: var(--primary-color, #1e3a5f);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.optional-badge {
    font-weight: 400;
    font-size: 0.72rem;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 0.125rem 0.5rem;
    border-radius: 3px;
    margin-left: auto;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.question-text {
    font-size: 0.9rem;
    color: #475569;
    line-height: 1.5;
    margin: -0.25rem 0 0.45rem 2.125rem;
}

.star-rating {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    direction: rtl;
    justify-content: flex-end;
    margin-left: 2.125rem;
}

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

.star-rating .star {
    font-size: 2rem;
    color: #e5e7eb;
    cursor: pointer;
    transition: color .15s, transform .15s;
    direction: ltr;
    user-select: none;
}

.star-rating .star:hover,
.star-rating .star:hover ~ .star,
.star-rating input[type="radio"]:checked ~ .star {
    color: #d97706;
}

.star-rating .star:hover {
    transform: scale(1.2);
}

.clear-rating {
    direction: ltr;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #d1d5db;
    cursor: pointer;
    padding: 0 0.5rem;
    line-height: 1;
    order: -1;
    transition: color .15s;
}

.clear-rating:hover {
    color: #ef4444;
}

/* --- Thank You & Invalid --- */
.thankyou-container,
.invalid-container {
    text-align: center;
    padding: 3.5rem 2rem;
}

.thankyou-icon,
.invalid-icon {
    font-size: 2.5rem;
    width: 4.5rem;
    height: 4.5rem;
    line-height: 4.5rem;
    border-radius: 6px;
    margin: 0 auto 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thankyou-icon {
    color: #16a34a;
    background: #f0fdf4;
    box-shadow: none;
    border: 1px solid #bbf7d0;
}

.invalid-icon {
    color: #d97706;
    background: #fffbeb;
    box-shadow: none;
    border: 1px solid #fde68a;
}

.thankyou-container h1 {
    color: #15803d;
    margin-bottom: 0.75rem;
}

.invalid-container h1 {
    color: #92400e;
    margin-bottom: 0.75rem;
}

.thankyou-container p,
.invalid-container p {
    color: #64748b;
    font-size: 1rem;
    max-width: 420px;
    margin: 0 auto;
    line-height: 1.6;
}

/* --- Admin --- */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

.admin-nav {
    display: flex;
    gap: 0.25rem;
    background: #f1f5f9;
    padding: 0.25rem;
    border-radius: 4px;
}

.admin-nav a {
    color: #64748b;
    text-decoration: none;
    padding: 0.44rem 0.875rem;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.85rem;
    transition: background .15s, color .15s;
}

.admin-nav a:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.admin-nav a.active {
    background: #fff;
    color: var(--primary-color, #1e3a5f);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    font-weight: 600;
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2.25rem;
}

.stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 1.125rem;
    text-align: center;
    transition: border-color .15s;
}

.stat-card:hover {
    border-color: #cbd5e1;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color, #1e3a5f);
    letter-spacing: -0.02em;
}

.stat-label {
    color: #94a3b8;
    font-size: 0.75rem;
    margin-top: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Data Table --- */
.table-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.table-card-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.table-card-header h2 {
    margin: 0;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid #f3f4f6;
}

.data-table th {
    background: transparent;
    font-weight: 600;
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
}

.data-table tbody tr {
    transition: background .15s;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.empty-state {
    text-align: center;
    color: #9ca3af;
    padding: 3rem 1rem !important;
    font-size: 0.95rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-pending { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-fetched { background: #dbeafe; color: #1e40af; }

.ratings-cell {
    white-space: nowrap;
}

.mini-rating {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    background: #f1f5f9;
    border-radius: 2px;
}

.mini-rating:not(:last-child) {
    margin-right: 0.125rem;
}

.comment-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #6b7280;
}

/* --- API Key Display --- */
.api-key-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #f8fafc;
    padding: 0.875rem 1.125rem;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    margin: 0.75rem 0;
}

.api-key-display code {
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.85rem;
    word-break: break-all;
    flex: 1;
    color: #334155;
}

/* --- Color Input --- */
.color-input-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-input-group input[type="color"] {
    width: 44px;
    height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    cursor: pointer;
    padding: 2px;
    background: #fff;
}

.color-value {
    font-family: 'SFMono-Regular', 'Consolas', monospace;
    color: #6b7280;
    font-size: 0.9rem;
}

/* --- API Docs --- */
.api-docs pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1.125rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.8rem;
    margin-bottom: 1rem;
    line-height: 1.7;
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
}

.api-docs h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: #374151;
}

/* --- Checkbox --- */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: #6b7280;
}

.current-logo {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.current-logo img {
    display: block;
    margin-bottom: 0.75rem;
}

/* --- Login page --- */
.login-container {
    text-align: center;
}

.login-icon {
    margin-bottom: 0.75rem;
}

.login-icon svg {
    width: 40px;
    height: 40px;
    color: #475569;
    stroke-width: 1.5;
}

.login-container h1 {
    margin-bottom: 0.5rem;
}

.login-subtitle {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.login-container .form-group {
    text-align: left;
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .site-header { padding: 0.75rem 1rem; }
    .survey-container,
    .admin-container { padding: 1.25rem; border-radius: 0; box-shadow: none; }
    .site-main { padding: 1rem 0; }
    .star-rating .star { font-size: 1.75rem; }
    .form-row { grid-template-columns: 1fr; }
    .driver-cards { grid-template-columns: 1fr; }
    .admin-header { flex-direction: column; align-items: flex-start; }
    .admin-nav { flex-wrap: wrap; width: 100%; }
    h1 { font-size: 1.4rem; }
    .step-header { padding: 1rem; }
    .step-body { padding: 1.25rem; }
    .question-group { padding: 1rem; }
    .survey-meta { flex-direction: column; gap: 0.375rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
