@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Shadcn Zinc Palette (Light Mode) */
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 240 5.9% 10%;
    --radius: 0.5rem;
}

.dark {
    /* Shadcn Zinc Palette (Dark Mode) */
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border-color: hsl(var(--border));
}

body {
    font-family: 'Inter', sans-serif;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    min-height: 100vh;
    padding: 2rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;

    /* Modern Background Pattern */
    background-image: radial-gradient(hsl(var(--foreground) / 0.1) 1px, transparent 1px);
    background-size: 24px 24px;
}

.container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: relative;
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    z-index: 1000;
}

.theme-toggle:hover {
    background-color: hsl(var(--accent));
    transform: translateY(-2px);
}

.theme-toggle:active {
    transform: translateY(0);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 1rem;
}

.header h1 {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
    color: hsl(var(--foreground));
}

.header p {
    font-size: 1.125rem;
    color: hsl(var(--muted-foreground));
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    align-items: start;
    /* Changed from stretch to start to allow natural height */
}

/* Section Cards (Mimicking shadcn Card) */
.section {
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    padding: 1.5rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    display: flex;
    /* Enable flex for vertical stacking */
    flex-direction: column;
}

/* Specific scrolling for user list */
.user-list {
    max-height: 261px;
    /* Constant height to match neighbor */
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Style scrollbar for user list */
.user-list::-webkit-scrollbar {
    width: 6px;
}

.user-list::-webkit-scrollbar-track {
    background: transparent;
}

.user-list::-webkit-scrollbar-thumb {
    background-color: hsl(var(--border));
    border-radius: 20px;
}

.payment-history-section {
    grid-column: 1 / -1;
    /* Span full width like balance section */
}

/* Scrollable Payment List (approx 10 items) */
.payment-history-section .payment-list {
    max-height: 600px;
    /* Adjust based on item height, roughly 60px-70px per item */
    overflow-y: auto;
    padding-right: 0.5rem;
}

.payment-history-section .payment-list::-webkit-scrollbar {
    width: 6px;
}

.payment-history-section .payment-list::-webkit-scrollbar-track {
    background: transparent;
}

.payment-history-section .payment-list::-webkit-scrollbar-thumb {
    background-color: hsl(var(--border));
    border-radius: 20px;
}

.section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: none;
    padding-bottom: 0;
}

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

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    height: 2.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--input));
    background-color: transparent;
    color: hsl(var(--foreground));
    font-size: 0.875rem;
    transition: box-shadow 0.15s ease-in-out;
    font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--border) / 0.3);
    /* Simulating ring */
}

/* Buttons */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    height: 2.5rem;
    padding: 0 1rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;

    /* Primary Button Style Default */
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
}

button:hover {
    opacity: 0.9;
}

button:active {
    transform: scale(0.98);
}

/* Destructive / Remove Button */
.remove-btn {
    background-color: transparent;
    color: hsl(var(--destructive));
    border: 1px solid hsl(var(--destructive) / 0.5);
    height: 2rem;
    width: auto;
    padding: 0 0.75rem;
    font-size: 0.75rem;
}

.remove-btn:hover {
    background-color: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    opacity: 1;
}

/* Lists */
.user-list,
.payment-list {
    list-style: none;
    margin-top: 1.5rem;
}

.user-item,
.payment-item {
    background-color: transparent;
    padding: 0.75rem 0;
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-item:last-child,
.payment-item:last-child {
    border-bottom: none;
}

.payment-item {
    padding: 1rem 0;
}


/* Radio & Checkbox */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    cursor: pointer;
}

.checkbox-item:hover {
    background-color: hsl(var(--accent));
}

input[type="radio"],
input[type="checkbox"] {
    accent-color: hsl(var(--primary));
    width: 1rem;
    height: 1rem;
    margin: 0;
}

/* Balance Section */
.balance-section {
    grid-column: 1 / -1;
    background-color: hsl(var(--accent) / 0.2);
    border: 1px solid hsl(var(--border));
}

.balance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.balance-card {
    background-color: hsl(var(--card));
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid hsl(var(--border));
}

.balance-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.debt-item {
    padding: 0.75rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid hsl(var(--border));
    font-size: 0.875rem;
}

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

.amount-positive {
    color: #10b981;
    /* Emerald 500 */
    font-weight: 600;
}

.amount-negative {
    color: #ef4444;
    /* Red 500 */
    font-weight: 600;
}

.payment-details {
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}

.empty-state {
    text-align: center;
    color: hsl(var(--muted-foreground));
    padding: 2rem;
    font-style: normal;
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    .theme-toggle {
        top: 1rem;
        right: 1rem;
    }
}