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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f9fafb;
    min-height: 100vh;
    color: #111827;
}

/* ---- Header ---- */
.header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    height: 28px;
    width: auto;
}

.auth-logo {
    display: block;
    margin: 0 auto 8px;
    height: 36px;
    width: auto;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: #374151;
}

.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: #6b7280;
    overflow: hidden;
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-logout {
    color: #6b7280;
    text-decoration: none;
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    transition: background 0.15s;
}

.header-logout:hover {
    background: #f3f4f6;
}

/* ---- Main layout ---- */
.main-layout {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex;
    gap: 24px;
}

.translator-panel {
    flex: 1;
    min-width: 0;
}

.history-panel {
    width: 320px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }
    .history-panel {
        width: 100%;
    }
}

/* ---- Form elements ---- */
label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

select, textarea, input[type="text"], input[type="email"], input[type="password"] {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1rem;
    color: #111827;
    background: #fff;
    font-family: inherit;
    outline: none;
}

select:focus, textarea:focus, input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

textarea {
    resize: none;
    padding: 12px 16px;
}

textarea.output {
    background: #f3f4f6;
}

/* ---- Lang row ---- */
.lang-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 16px;
}

.lang-group { flex: 1; }

.swap-btn {
    flex-shrink: 0;
    width: 40px;
    height: 38px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #4b5563;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.swap-btn:hover { background: #f3f4f6; }
.swap-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s;
    font-family: inherit;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-google {
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
    font-weight: 500;
}

.btn-google:hover { background: #f9fafb; }

/* ---- Translate button ---- */
.translate-btn {
    width: 100%;
    padding: 12px;
    background: #2563eb;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin: 16px 0;
}

.translate-btn:hover { background: #1d4ed8; }
.translate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Alerts ---- */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
}

.error-inline {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 0.875rem;
    display: none;
}

/* ---- Auth page ---- */
.auth-container {
    max-width: 420px;
    margin: 60px auto;
    padding: 0 16px;
}

.auth-title {
    text-align: center;
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 24px;
}

.auth-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
}

.auth-tab {
    flex: 1;
    padding: 8px 0 10px;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s;
}

.auth-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

.auth-tab-content {
    display: none;
}

.auth-tab-content.active {
    display: block;
}

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

.auth-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.auth-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e5e7eb;
}

.auth-divider span {
    background: #fff;
    padding: 0 12px;
    color: #9ca3af;
    font-size: 0.85rem;
    position: relative;
}

/* ---- History ---- */
.history-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
}

.history-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: #374151;
}

.history-list {
    max-height: 500px;
    overflow-y: auto;
}

.history-empty {
    color: #9ca3af;
    font-size: 0.875rem;
    text-align: center;
    padding: 24px 0;
}

.history-item {
    padding: 10px;
    border: 1px solid #f3f4f6;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: #f9fafb;
}

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

.history-langs {
    font-size: 0.75rem;
    font-weight: 600;
    color: #2563eb;
    text-transform: uppercase;
}

.history-delete {
    background: none;
    border: none;
    color: #d1d5db;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

.history-delete:hover {
    color: #ef4444;
}

.history-text {
    font-size: 0.85rem;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 4px;
}

/* ---- Main tabs (Text / Image) ---- */
.main-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
}

.main-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 0;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.main-tab:hover {
    color: #374151;
}

.main-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

.main-tab svg {
    flex-shrink: 0;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ---- Engine toggle ---- */
.engine-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 3px;
}

.engine-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.engine-btn.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.engine-btn:hover:not(.active) {
    color: #374151;
}

/* ---- Image mode toggle ---- */
.image-mode-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 3px;
}

.mode-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.mode-btn.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-btn:hover:not(.active) {
    color: #374151;
}

/* ---- Upload area ---- */
.upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    overflow: hidden;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: #3b82f6;
    background: #eff6ff;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    text-align: center;
}

.upload-placeholder p {
    margin-top: 12px;
    font-size: 0.95rem;
    color: #374151;
    font-weight: 500;
}

.upload-placeholder span {
    margin-top: 4px;
    font-size: 0.8rem;
    color: #9ca3af;
}

.upload-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 12px;
    min-height: 120px;
    background: #f9fafb;
}

.upload-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    object-fit: contain;
}

.upload-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s;
}

.upload-remove:hover {
    background: rgba(239, 68, 68, 0.8);
}

/* ---- Image history variant ---- */
.history-langs-image {
    color: #7c3aed;
}

.history-langs svg {
    vertical-align: -2px;
    margin-right: 3px;
}

.history-item-image {
    border-left: 3px solid #7c3aed;
}

/* ---- Document history variant ---- */
.history-langs-doc {
    color: #ea580c;
}

.history-item-doc {
    border-left: 3px solid #ea580c;
}

/* ---- Document file info ---- */
.doc-file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    position: relative;
    background: #f9fafb;
}

.doc-file-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: #6b7280;
    flex-shrink: 0;
}

.doc-type-pdf { background: #dc2626; }
.doc-type-txt { background: #2563eb; }
.doc-type-docx { background: #1d4ed8; }

.doc-file-details {
    flex: 1;
    min-width: 0;
}

.doc-file-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-file-size {
    font-size: 0.8rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* ---- Credits display in header ---- */
.credits-display {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 8px;
}

.credits-free {
    font-size: 0.75rem;
    color: #6b7280;
    background: #f3f4f6;
    padding: 4px 8px;
    border-radius: 6px;
}

.credits-badge {
    font-size: 0.8rem;
    font-weight: 600;
    color: #d97706;
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 4px 10px;
    border-radius: 6px;
}

.credits-buy-btn {
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    padding: 4px 12px;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.15s;
}

.credits-buy-btn:hover {
    background: #1d4ed8;
}

/* ---- Buy credits page ---- */
.buy-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 32px 16px;
}

.buy-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.buy-subtitle {
    text-align: center;
    color: #6b7280;
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.buy-costs {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.cost-item {
    font-size: 0.85rem;
    color: #374151;
    background: #f3f4f6;
    padding: 6px 14px;
    border-radius: 8px;
}

.currency-toggle {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 24px;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 3px;
    max-width: 200px;
    margin-left: auto;
    margin-right: auto;
}

.currency-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.currency-btn.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.packages-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

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

.package-card {
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    transition: border-color 0.15s, box-shadow 0.15s;
    position: relative;
}

.package-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.package-popular {
    border-color: #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.package-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #2563eb;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 12px;
    border-radius: 10px;
    text-transform: uppercase;
}

.package-credits {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 8px;
}

.package-price {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2563eb;
    margin-bottom: 4px;
}

.package-discount {
    font-size: 0.75rem;
    color: #16a34a;
    font-weight: 500;
    margin-bottom: 12px;
}

.package-buy-btn {
    width: 100%;
    padding: 10px;
    background: #2563eb;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 8px;
}

.package-buy-btn:hover {
    background: #1d4ed8;
}

.package-buy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.buy-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.875rem;
    text-align: center;
}

/* ---- Payment success ---- */
.payment-success-card {
    text-align: center;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 40px 24px;
    margin-top: 20px;
}

.payment-success-icon {
    margin-bottom: 16px;
}

.payment-success-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #16a34a;
    margin-bottom: 8px;
}

.payment-success-card p {
    color: #6b7280;
    margin-bottom: 8px;
}

.payment-balance {
    font-size: 1.1rem;
    color: #111827 !important;
}

/* ---- Admin page ---- */
.admin-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;
}

.admin-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
}

.admin-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.admin-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 12px;
}

.admin-search-form {
    display: flex;
    gap: 8px;
}

.admin-search-input {
    flex: 1;
}

.admin-user-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-grant-form {
    border-top: 1px solid #f3f4f6;
    padding-top: 12px;
}

.admin-grant-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.admin-grant-input {
    flex: 1;
    min-width: 100px;
}

.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th,
.admin-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #f3f4f6;
}

.admin-table th {
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.tx-positive {
    color: #16a34a;
    font-weight: 600;
}

.tx-negative {
    color: #dc2626;
    font-weight: 600;
}

.tx-type {
    font-size: 0.75rem;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 4px;
    color: #6b7280;
}

/* ---- Header avatar link ---- */
.header-avatar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #374151;
    font-size: 0.875rem;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.15s;
}

.header-avatar-link:hover {
    background: #f3f4f6;
}

/* ---- Profile page ---- */
.profile-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px 16px;
}

.profile-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
}

.profile-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.profile-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 16px;
}

.profile-avatar-section {
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.5rem;
    color: #6b7280;
    overflow: hidden;
    flex-shrink: 0;
}

.profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-actions {
    flex: 1;
}

.profile-avatar-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-avatar-name {
    font-size: 0.8rem;
    color: #6b7280;
}

.profile-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

.profile-btn:hover {
    background: #f3f4f6;
}

.profile-btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.profile-btn-primary:hover {
    background: #1d4ed8;
}

.profile-btn-danger {
    color: #dc2626;
    border-color: #fecaca;
}

.profile-btn-danger:hover {
    background: #fef2f2;
}

.profile-hint {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 8px;
}

.profile-credits-info {
    display: flex;
    gap: 24px;
}

.profile-credit-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.profile-credit-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
}

.profile-credit-label {
    font-size: 0.8rem;
    color: #6b7280;
}

/* ---- Download button ---- */
.download-btn {
    width: 100%;
    padding: 12px;
    background: #16a34a;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.download-btn:hover { background: #15803d; }
.download-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 600px) {
    .credits-display {
        gap: 4px;
    }
    .credits-free {
        display: none;
    }
    .admin-grant-row {
        flex-direction: column;
    }
    .admin-grant-input {
        width: 100%;
    }
    .profile-avatar-section {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
}
