/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --background: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 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);
    --radius: 12px;
    --radius-sm: 8px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Card Styles */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Input Groups */
.input-group {
    margin-bottom: 16px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* Input with Prefix/Suffix */
.input-with-prefix,
.input-with-suffix {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-prefix input {
    padding-left: 32px;
}

.input-with-suffix input {
    padding-right: 32px;
}

.prefix, .suffix {
    position: absolute;
    color: var(--text-secondary);
    font-weight: 500;
    pointer-events: none;
}

.prefix {
    left: 12px;
}

.suffix {
    right: 12px;
}

/* Base Input Styles */
input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Stepper */
.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stepper input {
    width: 80px;
    text-align: center;
    font-weight: 600;
}

.stepper-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stepper-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.stepper-btn:active {
    transform: scale(0.95);
}

/* Tip Buttons */
.tip-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.tip-btn {
    padding: 12px 8px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tip-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

/* Custom Tip */
.custom-tip {
    margin-bottom: 16px;
}

.tip-amount-display {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

#tip-amount-value {
    color: var(--primary-color);
    font-weight: 600;
}

/* Split Toggle */
.split-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.split-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.split-btn:hover {
    border-color: var(--primary-color);
}

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

/* Unequal Split */
.hidden {
    display: none !important;
}

.unequal-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.split-mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

/* People Inputs */
#people-inputs {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.person-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.person-name {
    flex: 1;
    min-width: 0;
}

.person-name input {
    width: 100%;
}

.person-value {
    width: 100px;
}

.person-value .input-with-prefix input,
.person-value .input-with-suffix input {
    width: 100%;
}

.person-share {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 70px;
    text-align: right;
}

/* Remaining Indicator */
.remaining-indicator {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: #fef3c7;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.remaining-indicator.balanced {
    background: #d1fae5;
}

#remaining-value {
    font-weight: 600;
}

/* Results Section */
.results-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.results-card h2 {
    color: white;
}

.result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 0.9375rem;
}

.result-row.total-row {
    font-size: 1.125rem;
    font-weight: 600;
    padding: 12px 0;
}

.result-row.highlight {
    font-size: 1.25rem;
    font-weight: 700;
    padding: 12px 0;
}

.results-card hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    margin: 8px 0;
}

/* Individual Shares (for unequal split) */
.individual-share {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
}

/* Share Button */
.share-btn {
    width: 100%;
    margin-top: 16px;
    padding: 14px;
    border: 2px solid white;
    border-radius: var(--radius-sm);
    background: transparent;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

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

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

/* Footer */
footer {
    margin-top: 24px;
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-body textarea {
    width: 100%;
    height: 150px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    resize: none;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.share-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--primary-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

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

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

.action-btn:first-child:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 1001;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .tip-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .person-row {
        flex-wrap: wrap;
    }

    .person-name {
        flex: 1 1 100%;
    }

    .person-value {
        flex: 1;
    }

    .person-share {
        min-width: auto;
    }

    .share-actions {
        flex-direction: column;
    }
}

@media (min-width: 768px) {
    .container {
        padding: 40px 20px;
    }

    .card {
        padding: 24px;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.3s ease-out;
}

.card:nth-child(2) {
    animation-delay: 0.1s;
}

.card:nth-child(3) {
    animation-delay: 0.2s;
}

.card:nth-child(4) {
    animation-delay: 0.3s;
}

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

button:focus:not(:focus-visible) {
    outline: none;
}
