/* ============================================================================
   Hisaab - Main Stylesheet
   A clean, simple design for expense tracking
   ============================================================================ */

/* CSS Variables */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-info: #0891b2;
    --color-info-light: #cffafe;
    
    --color-bg: #f8fafc;
    --color-bg-white: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;
    
    --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);
    
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1, h2, h3, h4 {
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    line-height: 1.25;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

p {
    margin: 0 0 1rem 0;
}

/* Layout */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
}

main.container {
    flex: 1;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

/* Navbar */
.navbar {
    background: var(--color-bg-white);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.logo:hover {
    text-decoration: none;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
}

.user-info:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.user-name {
    color: var(--color-text);
}

/* Avatar */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-sm {
    width: 24px;
    height: 24px;
}

.avatar-lg {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
}

.avatar-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
    font-size: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

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

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

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

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

.btn-outline {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover {
    background: var(--color-bg);
    border-color: var(--color-text-muted);
}

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

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-google {
    background: white;
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-google:hover {
    background: var(--color-bg);
    box-shadow: var(--shadow);
}

.google-icon {
    width: 20px;
    height: 20px;
}

/* Cards */
.card {
    background: var(--color-bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
}

.alert-success {
    background: var(--color-success-light);
    color: var(--color-success);
}

.alert-error {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.alert-warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.alert-info {
    background: var(--color-info-light);
    color: var(--color-info);
}

.alert-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.6;
    color: inherit;
}

.alert-close:hover {
    opacity: 1;
}

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

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-white);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-control::placeholder {
    color: var(--color-text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-inline {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.form-inline .form-group {
    margin-bottom: 0;
    flex: 1;
}

.form-help {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.375rem;
}

.form-errors {
    margin-top: 0.375rem;
}

.form-errors .error {
    display: block;
    color: var(--color-danger);
    font-size: 0.8125rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.inline-form {
    display: inline;
}

/* Checkbox & Radio */
.checkbox-group,
.split-type-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.checkbox-label,
.radio-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9375rem;
}

.checkbox-label input,
.radio-label input {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

/* Page Header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin-bottom: 0.25rem;
}

.back-link {
    display: inline-block;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.page-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.trip-summary {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
    margin: 0;
}

/* Trips Grid */
.trips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.trip-card {
    background: var(--color-bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    text-decoration: none;
    color: var(--color-text);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.trip-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
}

.trip-name {
    margin-bottom: 0.75rem;
    font-size: 1.125rem;
}

.trip-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.trip-stat {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.trip-date {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.create-trip-card {
    background: var(--color-primary-light);
    border: 2px dashed var(--color-primary);
}

.create-trip-card h2 {
    border-bottom: none;
    padding-bottom: 0;
}

/* Participants */
.participants-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.participant-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border-light);
}

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

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

.participant-name {
    font-weight: 500;
}

.badge {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    margin-left: 0.5rem;
}

.badge-owner {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.invites-list {
    margin-bottom: 1.5rem;
}

.invite-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border-light);
}

.invite-email {
    flex: 1;
}

.invite-status {
    font-size: 0.8125rem;
    color: var(--color-warning);
}

.add-participant-form {
    border-top: 1px solid var(--color-border-light);
    padding-top: 1rem;
    margin-top: 1rem;
}

.add-participant-form h3 {
    margin-bottom: 0.75rem;
}

/* Expenses Table */
.expenses-table-wrapper {
    overflow-x: auto;
}

.expenses-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.expenses-table th,
.expenses-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
}

.expenses-table th {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.expenses-table tbody tr:hover {
    background: var(--color-bg);
}

.expense-date {
    white-space: nowrap;
    color: var(--color-text-muted);
}

.expense-amount {
    font-weight: 600;
    white-space: nowrap;
}

.expense-payer {
    white-space: nowrap;
}

.expense-row {
    cursor: pointer;
    transition: background 0.15s ease;
}

.expense-row:hover {
    background: var(--color-bg);
}

.split-summary {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.split-preview {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.split-count {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.split-toggle {
    font-size: 0.625rem;
    color: var(--color-text-muted);
    transition: transform 0.2s ease;
}

.expense-row.expanded .split-toggle {
    transform: rotate(180deg);
}

.split-breakdown {
    display: none;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--color-border-light);
}

.expense-row.expanded .split-breakdown {
    display: block;
}

.split-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    font-size: 0.8125rem;
}

.split-name {
    color: var(--color-text);
    font-weight: 500;
}

.split-amount {
    color: var(--color-text-muted);
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.75rem;
}

.expense-actions {
    text-align: right;
}

/* Settlement */
.section-desc {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
    margin-bottom: 1rem;
}

.balances-table-wrapper {
    overflow-x: auto;
}

.balances-table {
    width: 100%;
    border-collapse: collapse;
}

.balances-table th,
.balances-table td {
    padding: 0.875rem 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
}

.balances-table th {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.text-right {
    text-align: right;
}

.person-name {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.balance-positive {
    color: var(--color-success);
}

.balance-negative {
    color: var(--color-danger);
}

.balance-label {
    font-size: 0.75rem;
    font-weight: 400;
    display: block;
}

.balance-settled {
    color: var(--color-text-muted);
}

/* Transfers */
.transfers-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.transfer-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

.transfer-from,
.transfer-to {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.transfer-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.arrow {
    font-size: 1.25rem;
    color: var(--color-text-muted);
}

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

.settlement-summary {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border-light);
    text-align: center;
    color: var(--color-text-muted);
}

.all-settled {
    font-size: 1.5rem;
    color: var(--color-success);
    margin-bottom: 0.5rem;
}

.quick-reference {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.reference-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border-light);
}

.reference-amount {
    font-weight: 600;
    color: var(--color-primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--color-bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 1rem;
}

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

/* Danger Zone */
.danger-zone {
    border: 1px solid var(--color-danger-light);
}

.danger-zone h2 {
    color: var(--color-danger);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-muted);
}

/* Error Pages */
.error-page {
    text-align: center;
    padding: 4rem 1rem;
}

.error-page h1 {
    font-size: 6rem;
    color: var(--color-text-muted);
    margin-bottom: 0;
}

.error-page h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.error-page p {
    color: var(--color-text-muted);
    margin-bottom: 2rem;
}

/* Auth Page */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
}

.auth-card {
    background: var(--color-bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.auth-card h1 {
    margin-bottom: 0.5rem;
}

.auth-card .subtitle {
    color: var(--color-text-muted);
    margin-bottom: 2rem;
}

.features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
    text-align: left;
}

.feature {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.feature-icon {
    font-size: 1.25rem;
}

.auth-card .btn-google {
    width: 100%;
    margin-bottom: 1.5rem;
}

.terms {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin: 0;
}

/* Footer */
.footer {
    background: var(--color-bg-white);
    border-top: 1px solid var(--color-border);
    padding: 1rem 0;
    margin-top: auto;
}

.footer p {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: 0;
}

/* Profile Page */
.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.profile-info h2 {
    margin-bottom: 0.25rem;
}

.profile-info .text-muted {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin: 0;
}

.divider {
    border: none;
    border-top: 1px solid var(--color-border-light);
    margin: 1.5rem 0;
}

.display-name-preview {
    background: var(--color-bg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin: 0;
}

.display-name-preview .text-muted {
    font-size: 0.8125rem;
    margin-left: 0.5rem;
}

/* Responsive */
@media (max-width: 640px) {
    .page-title-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .transfer-item {
        flex-direction: column;
        text-align: center;
    }
    
    .transfer-arrow {
        flex-direction: row;
        gap: 0.5rem;
    }
    
    .features {
        grid-template-columns: 1fr;
    }
    
    .trips-grid {
        grid-template-columns: 1fr;
    }
}
