/* CSS Variables */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --success-hover: #059669;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --radius-sm: 0.375rem;
    --radius: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --radius-full: 9999px;

    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.6;
}

/* App Container */
.app-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Language Selector */
.language-selector {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

.language-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-full);
    color: var(--white);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.language-toggle .current-flag {
    font-size: 1.125rem;
}

.language-toggle .current-lang {
    display: none;
}

.language-toggle .chevron {
    width: 1rem;
    height: 1rem;
    transition: transform 0.2s ease;
}

.language-toggle[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.language-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 160px;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: dropdownIn 0.2s ease;
}

.language-dropdown.hidden {
    display: none;
}

.language-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: var(--transition);
}

.language-option:hover {
    background: var(--gray-50);
}

.language-option.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.language-option .lang-flag {
    font-size: 1.25rem;
}

.language-option .lang-name {
    flex: 1;
}

@keyframes dropdownIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.header {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--white);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    width: 2.5rem;
    height: 2.5rem;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
}

.domain-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.375rem;
    letter-spacing: 0.5px;
}

/* Add Person Section */
.add-person-section {
    margin-bottom: 1.5rem;
}

.add-person-form {
    display: flex;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    padding: 1rem;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.add-person-input-wrapper {
    flex: 1;
    position: relative;
}

.add-person-input-wrapper .input-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.25rem;
    height: 1.25rem;
    color: var(--gray-400);
    pointer-events: none;
}

.add-person-input-wrapper input {
    padding-left: 2.75rem;
    border: none;
    background: var(--white);
    border-radius: var(--radius-lg);
}

.add-person-input-wrapper input:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.btn-add-person {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
}

/* People Cards Section */
.people-cards-section {
    margin-bottom: 1rem;
}

.people-cards-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Empty State */
.empty-state {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--white);
    border: 2px dashed rgba(255, 255, 255, 0.3);
}

.empty-state.hidden {
    display: none;
}

.empty-state-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 1rem;
    opacity: 0.7;
}

.empty-state-icon svg {
    width: 100%;
    height: 100%;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-state p {
    opacity: 0.8;
    font-size: 0.9375rem;
}

/* Person Card */
.person-card {
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: cardIn 0.3s ease;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.person-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
}

.person-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.person-avatar {
    width: 2.75rem;
    height: 2.75rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    text-transform: uppercase;
}

.person-details h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.person-total {
    font-size: 0.875rem;
    opacity: 0.9;
}

.person-total-amount {
    font-weight: 700;
}

.btn-remove-person {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: var(--white);
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-remove-person:hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn-remove-person svg {
    width: 1rem;
    height: 1rem;
}

/* Person Card Content */
.person-card-content {
    padding: 1rem 1.25rem;
}

/* Add Expense Form in Card */
.add-expense-inline {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.add-expense-inline input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    border-radius: var(--radius-md);
}

.add-expense-inline .expense-amount-input {
    width: 100px;
    flex: none;
}

.btn-add-expense-inline {
    padding: 0.625rem;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: var(--white);
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn-add-expense-inline:hover {
    background: var(--primary-hover);
}

.btn-add-expense-inline svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Person Expenses List */
.person-expenses {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.person-expense-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.75rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    animation: slideIn 0.2s ease;
}

.person-expense-item:hover {
    background: var(--gray-100);
}

.expense-item-info {
    flex: 1;
    min-width: 0;
}

.expense-item-description {
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.expense-item-amount {
    font-weight: 700;
    color: var(--gray-800);
    font-size: 0.9375rem;
    margin-left: 1rem;
}

.btn-remove-expense {
    background: transparent;
    border: none;
    color: var(--gray-400);
    padding: 0.375rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin-left: 0.5rem;
}

.btn-remove-expense:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.btn-remove-expense svg {
    width: 1rem;
    height: 1rem;
}

.no-expenses-msg {
    text-align: center;
    color: var(--gray-400);
    font-size: 0.875rem;
    padding: 1rem;
}

/* Calculate Card */
.calculate-card {
    padding: 1.25rem;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    margin-bottom: 1rem;
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.step-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
}

.card-content {
    padding: 1.5rem;
}

/* Input Group */
.input-group {
    display: flex;
    gap: 0.5rem;
}

.input-group input {
    flex: 1;
}

/* Form Elements */
input, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 1rem;
    color: var(--gray-800);
    background: var(--white);
    transition: var(--transition);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder {
    color: var(--gray-400);
}

input:disabled, select:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Amount Input */
.amount-input {
    position: relative;
    flex: 1;
}

.currency-symbol {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-500);
    font-weight: 500;
}

.amount-input input {
    padding-left: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn svg {
    width: 1.125rem;
    height: 1.125rem;
}

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

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

.btn-ghost {
    background: transparent;
    color: var(--gray-500);
    padding: 0.5rem;
}

.btn-ghost:hover {
    background: var(--gray-100);
    color: var(--danger);
}

.btn-large {
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1.0625rem;
}

/* Expense Form */
.expense-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-row select {
    flex: 1;
}

.form-row input[type="text"] {
    flex: 2;
}

/* People List */
.people-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.person-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-full);
    font-weight: 500;
    font-size: 0.9375rem;
    animation: slideIn 0.2s ease;
}

.person-tag button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--primary);
    opacity: 0.7;
    transition: var(--transition);
    border-radius: var(--radius-full);
}

.person-tag button:hover {
    opacity: 1;
    background: rgba(99, 102, 241, 0.2);
}

.person-tag button svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* Expenses List */
.expenses-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.expense-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    animation: slideIn 0.2s ease;
}

.expense-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.expense-description {
    font-weight: 500;
    color: var(--gray-800);
}

.expense-meta {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.expense-amount {
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--gray-800);
}

.expense-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Empty Message */
.empty-message {
    text-align: center;
    color: var(--gray-400);
    padding: 1.5rem;
    font-size: 0.9375rem;
}

.people-list:not(:empty) + .empty-message,
.expenses-list:not(:empty) + .empty-message {
    display: none;
}

/* Results */
.results-container {
    margin-top: 1.5rem;
}

.results-container.hidden {
    display: none;
}

.results-summary {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.summary-title {
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.75rem;
    font-size: 0.9375rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--gray-200);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-item .name {
    color: var(--gray-600);
}

.summary-item .paid {
    color: var(--success);
    font-weight: 600;
}

.summary-item .share {
    color: var(--gray-500);
    font-size: 0.875rem;
}

.summary-total {
    display: flex;
    justify-content: space-between;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    border-top: 2px solid var(--gray-200);
    font-weight: 700;
}

.settlements {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.settlement-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--success-light);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--success);
}

.settlement-item.balanced {
    background: var(--primary-light);
    border-left-color: var(--primary);
}

.settlement-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.settlement-text .from {
    font-weight: 600;
    color: var(--gray-800);
}

.settlement-text .arrow {
    color: var(--gray-400);
}

.settlement-text .to {
    font-weight: 600;
    color: var(--gray-800);
}

.settlement-amount {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--success);
}

.settlement-item.balanced .settlement-amount {
    color: var(--primary);
}

.all-settled {
    text-align: center;
    padding: 1.5rem;
    background: var(--success-light);
    border-radius: var(--radius-lg);
    color: var(--success);
}

.all-settled svg {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.5rem;
}

.all-settled p {
    font-weight: 600;
    font-size: 1.0625rem;
}

/* Reset Container */
.reset-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem 1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: auto;
}

.footer p {
    font-size: 0.875rem;
}

.footer-note {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.2s ease;
}

.modal-content h3 {
    font-size: 1.125rem;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: var(--gray-600);
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 480px) {
    .app-container {
        padding: 0.75rem;
        padding-top: 3.5rem;
    }

    .language-selector {
        top: 0.75rem;
        right: 0.75rem;
    }

    .header {
        padding: 1rem 0.5rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .logo-icon {
        width: 2rem;
        height: 2rem;
    }

    /* Add Person Form Mobile */
    .add-person-form {
        flex-direction: column;
        padding: 0.875rem;
    }

    .btn-add-person {
        width: 100%;
        justify-content: center;
    }

    /* Person Card Mobile */
    .person-card-header {
        padding: 0.875rem 1rem;
    }

    .person-avatar {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1rem;
    }

    .person-details h3 {
        font-size: 1rem;
    }

    .person-card-content {
        padding: 0.875rem 1rem;
    }

    .add-expense-inline {
        flex-wrap: wrap;
    }

    .add-expense-inline input:first-child {
        width: 100%;
        flex: none;
    }

    .add-expense-inline .expense-amount-input {
        flex: 1;
    }

    /* Empty State Mobile */
    .empty-state {
        padding: 2rem 1.5rem;
    }

    .empty-state-icon {
        width: 3rem;
        height: 3rem;
    }

    .empty-state h3 {
        font-size: 1.125rem;
    }

    .card-header {
        padding: 1rem 1.25rem;
    }

    .card-content {
        padding: 1.25rem;
    }

    .input-group {
        flex-direction: column;
    }

    .input-group .btn {
        width: 100%;
    }

    .form-row {
        flex-direction: column;
    }

    .expense-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .expense-actions {
        width: 100%;
        justify-content: space-between;
    }

    .settlement-item {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn {
        width: 100%;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .app-container {
        max-width: 560px;
    }
}

@media (min-width: 769px) {
    .app-container {
        padding: 1.5rem;
    }

    .header {
        padding: 2.5rem 1rem;
    }

    .logo h1 {
        font-size: 2rem;
    }

    .language-toggle .current-lang {
        display: inline;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
    }

    .header, .footer, .reset-container, .btn, form, .language-selector {
        display: none;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--gray-200);
    }
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
