/* CSS Reset and Variables */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors - Shadcn inspired neutral palette */
    --background: #ffffff;
    --foreground: #0a0a0a;
    --card: #ffffff;
    --card-foreground: #0a0a0a;
    --primary: #171717;
    --primary-foreground: #fafafa;
    --secondary: #f5f5f5;
    --secondary-foreground: #171717;
    --muted: #f5f5f5;
    --muted-foreground: #737373;
    --accent: #f5f5f5;
    --accent-foreground: #171717;
    --destructive: #ef4444;
    --destructive-foreground: #fafafa;
    --border: #e5e5e5;
    --input: #e5e5e5;
    --ring: #0a0a0a;

    /* Spacing */
    --radius: 0.5rem;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    line-height: 1.5;
    min-height: 100vh;
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

/* Card */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.card-header {
    padding: 1.5rem 1.5rem 0;
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--card-foreground);
}

.card-description {
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

.card-content {
    padding: 1.5rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1rem;
}

.form-group:last-of-type {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--foreground);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select {
    width: 100%;
    height: 2.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: inherit;
    background-color: var(--background);
    border: 1px solid var(--input);
    border-radius: var(--radius);
    color: var(--foreground);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--muted);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgba(10, 10, 10, 0.1);
}

input::placeholder {
    color: var(--muted-foreground);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    height: 2.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

.btn-primary:hover:not(:disabled) {
    background-color: rgba(23, 23, 23, 0.9);
}

.btn-secondary {
    background-color: var(--secondary);
    color: var(--secondary-foreground);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(245, 245, 245, 0.8);
}

.btn-destructive {
    background-color: var(--destructive);
    color: var(--destructive-foreground);
}

.btn-destructive:hover:not(:disabled) {
    background-color: rgba(239, 68, 68, 0.9);
}

.btn-full {
    width: 100%;
}

/* Alert/Error Messages */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.alert-success {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.hidden {
    display: none;
}

/* Login Page Specific */
.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

/* Dashboard Specific */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.dashboard-logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--foreground);
    line-height: 0;
}

.dashboard-main {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem;
}

.dashboard-content {
    text-align: center;
}

.dashboard-greeting {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--foreground);
    margin-bottom: 0.5rem;
}

.dashboard-subtitle {
    font-size: 1.125rem;
    color: var(--muted-foreground);
}

/* Spinner */
.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 640px) {
    .dashboard-greeting {
        font-size: 1.75rem;
    }

    .dashboard-header {
        padding: 1rem;
    }

    .materials-grid {
        grid-template-columns: 1fr;
    }
}

/* Materials Grid */
.materials-container {
    width: 100%;
    max-width: 1200px;
    padding: 1rem 2rem 2rem;
}

.materials-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.material-card {
    display: flex;
    flex-direction: column;
}

.material-card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.material-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.material-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--foreground);
    letter-spacing: -0.015em;
    margin: 0;
}

.material-price-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.material-price {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted-foreground);
}

.btn-icon-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--background);
    color: var(--muted-foreground);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon-small:hover {
    background-color: var(--muted);
    color: var(--foreground);
    border-color: var(--foreground);
}

.material-card-content {
    padding: 1rem 1.5rem;
}

.profiles-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.profile-item {
    padding: 0.625rem 0.75rem;
    margin: 0.25rem 0;
    font-size: 0.875rem;
    color: var(--muted-foreground);
    background: var(--secondary);
    border-radius: calc(var(--radius) - 2px);
    transition: background-color 0.15s ease;
}

.profile-item:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

/* Loading State */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted-foreground);
}

.loading-spinner .spinner {
    width: 2rem;
    height: 2rem;
    margin-bottom: 1rem;
}

/* Empty & Error States */
.empty-state,
.error-message {
    text-align: center;
    padding: 3rem;
    color: var(--muted-foreground);
}

/* Profile Link Styles */
.profile-link {
    display: block;
    color: inherit;
    text-decoration: none;
    margin: -0.625rem -0.75rem;
    padding: 0.625rem 0.75rem;
}

.profile-item:has(.profile-link):hover {
    background: var(--primary);
    color: var(--primary-foreground);
}

/* Profile Page */
.profile-main {
    flex: 1;
    padding: 2rem;
}

.profile-container {
    max-width: 1200px;
    margin: 0 auto;
}

.profile-breadcrumb {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin-bottom: 0.25rem;
}

.profile-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: -0.025em;
}

/* Back Link */
.header-left {
    display: flex;
    align-items: center;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--foreground);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    transition: background-color 0.15s ease;
}

.back-link:hover {
    background: var(--secondary);
}

/* Shadcn-style Table */
.table-wrapper {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table-caption {
    padding: 1rem;
    font-size: 0.875rem;
    color: var(--muted-foreground);
    text-align: left;
    caption-side: bottom;
    border-top: 1px solid var(--border);
}

.data-table thead {
    background: var(--muted);
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 500;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem 1rem;
    color: var(--foreground);
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--muted);
}

.data-table .font-medium {
    font-weight: 500;
}

.table-footer {
    text-align: right;
    color: var(--muted-foreground);
    font-weight: 500;
}

/* Icon Buttons */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--background);
    color: var(--foreground);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background-color: var(--muted);
}

.btn-icon-success {
    color: #10b981;
}

.btn-icon-success:hover {
    background-color: #f0fdf4;
    border-color: #10b981;
}

.btn-icon-danger {
    color: var(--destructive);
}

.btn-icon-danger:hover {
    background-color: #fef2f2;
    border-color: var(--destructive);
}

/* Entry Card */
.entry-card {
    margin-bottom: 2rem;
    padding: 1.5rem;
}

.entry-card .form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.entry-card .form-row:last-child {
    margin-bottom: 0;
}

.form-actions {
    display: flex;
    align-items: flex-start;
    padding-top: 1.75rem;
}

.form-actions .btn {
    width: 100%;
}

/* Profile Header */
.profile-header {
    margin-bottom: 2rem;
}

/* Auto-filled info display */
.auto-filled-info {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.info-label {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    font-weight: 500;
}

.info-value {
    font-size: 0.875rem;
    color: var(--foreground);
    font-weight: 500;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.98) translateY(4px);
    transition: transform 0.18s ease;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0;
}

.modal-description {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin: 0.5rem 0 0 0;
    line-height: 1.5;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    border-top: 1px solid var(--border);
}

.modal-footer .btn {
    flex: 1;
    max-width: 120px;
}

.modal-footer .btn-danger {
    background-color: var(--destructive);
    color: var(--destructive-foreground);
}

.modal-footer .btn-danger:hover {
    background-color: #dc2626;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-form .form-group {
    margin: 0;
}

/* Table Wrapper for Horizontal Scroll */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.pagination-info {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    margin: 0 1rem;
    font-weight: 500;
}

.pagination-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--foreground);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    font-family: var(--font-sans);
    min-width: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--muted);
    border-color: var(--ring);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
}

/* Material Statistics */
.material-statistics {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.material-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.material-stat-label {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    font-weight: 500;
}

.material-stat-value {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

/* Statistics */
.statistics-container {
    margin-bottom: 2rem;
}

.statistics-card {
    background: var(--card);
}

.statistics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.stat-item {
    text-align: center;
    padding: 1.5rem 1rem;
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.stat-item:hover {
    background: var(--secondary);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--muted-foreground);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-values {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.stat-metric {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    font-weight: 500;
}

.stat-count,
.stat-weight {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

/* Responsive */
@media (max-width: 768px) {
    .statistics-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stat-item {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    .modal {
        width: 95%;
        margin: 1rem;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        max-width: none;
    }
    
    .pagination-container {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    .pagination-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.8125rem;
        min-width: 2rem;
    }
    
    .pagination-info {
        width: 100%;
        text-align: center;
        margin: 0.5rem 0;
    }
}
