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

:root {
    --primary-color: #FF6B35;
    --primary-dark: #E55A2B;
    --secondary-color: #F7931E;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --success-color: #4CAF50;
    --reject-color: #f44336;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    margin: 0 auto;
    background-color: var(--background);
}

.app-main.locked {
    pointer-events: none;
    opacity: 0.3;
    filter: blur(3px);
}

/* Login Modal */
.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #041f2d 0%, #0a3044 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-modal.hidden {
    display: none;
}

.login-modal-content {
    background: #15181d;
    border-radius: 16px;
    padding: 3rem;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.login-modal-header h1 {
    color: var(--primary-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.login-modal-subtitle {
    color: #c9e7f7;
    font-size: 1rem;
    margin-bottom: 2rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.login-form .form-group {
    text-align: left;
}

.login-form .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #eaf6ff;
    font-weight: 500;
    font-size: 0.95rem;
    line-height: 1.4;
}

.login-form .form-group input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1.1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    background: white;
    color: var(--text-primary);
}

.login-form .form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.login-error {
    color: var(--reject-color);
    font-size: 0.9rem;
    margin-top: -0.5rem;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 1.5rem 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    text-align: center;
}

.subtitle-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin: 0 auto;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.95;
    font-weight: 500;
}

.btn.btn-header-logout {
    width: auto;
    margin-top: 0;
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 10px;
    min-width: 90px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: none;
}

.btn-header-logout:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: none;
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.35rem;
        line-height: 1.2;
        text-align: center;
    }

    .subtitle-row {
        gap: 0.45rem;
    }

    .btn.btn-header-logout {
        min-width: 78px;
        padding: 0.42rem 0.62rem;
        font-size: 0.78rem;
        white-space: nowrap;
    }
}

@media (hover: none) and (pointer: coarse) {
    .btn.btn-header-logout {
        padding: 0.4rem 0.7rem;
        font-size: 0.82rem;
    }
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 2px solid var(--border-color);
    position: static;
    top: auto;
    z-index: auto;
    box-shadow: none;
    gap: 0;
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    font-family: inherit;
    touch-action: manipulation;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: rgba(255, 107, 53, 0.05);
}

.tab-btn:active {
    background: rgba(255, 107, 53, 0.1);
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Main Content */
.app-main {
    flex: 1;
    padding: 1rem;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding-bottom: 2rem;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

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

/* Forms */
.form {
    margin-top: 0.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95rem;
}

.optional {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85rem;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1.1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    background: var(--surface);
    color: var(--text-primary);
    -webkit-appearance: none;
    appearance: none;
}

.form-group input[readonly] {
    background-color: #e0e0e0;
    color: #424242;
    border-color: #bdbdbd;
}

.form-group input[type="password"] {
    font-size: 1.1rem;
    letter-spacing: 0.08em;
    -webkit-text-security: disc;
}

.form-group input[type="password"]::placeholder {
    letter-spacing: normal;
}

.form-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.form-group select {
    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='%23757575' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 12px;
    padding-right: 2.5rem;
}

.form-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.checkbox-group {
    margin-top: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 24px;
    height: 24px;
    margin-right: 0.75rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.checkbox-label span {
    font-size: 1rem;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    width: 100%;
    margin-top: 0.5rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 107, 53, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.btn-secondary {
    background: #1976d2;
    color: white;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.25);
}

.btn-secondary:hover {
    background: #1565c0;
    transform: translateY(-2px);
}

.btn-danger {
    background: var(--reject-color);
    color: white;
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.25);
}

.btn-danger:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

.btn-tertiary {
    background: #757575;
    color: white;
    box-shadow: 0 4px 12px rgba(117, 117, 117, 0.25);
    margin-top: 0.75rem;
    width: 100%;
}

.btn-tertiary:hover {
    background: #616161;
    transform: translateY(-2px);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    width: auto;
    margin: 0 0.2rem;
    margin-top: 0;
}

.track-table tfoot tr {
    background: rgba(255, 107, 53, 0.08);
    font-weight: 600;
}

.track-table tfoot th,
.track-table tfoot td {
    padding: 1rem 0.75rem;
    border-top: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.track-summary-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.track-summary-row:hover {
    background: rgba(255, 107, 53, 0.08);
}

.track-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.section-title-row h2 {
    margin-bottom: 0;
}

.section-title-row-compact {
    margin-bottom: 0.35rem;
}

.section-back-btn {
    width: auto;
    margin-top: 0;
    white-space: nowrap;
}

.track-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
    min-width: 0;
}

.filter-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
    min-width: 0;
}

.filter-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-row-dates {
    display: flex;
    gap: 0.35rem;
    width: 100%;
    align-items: center;
}

.filter-row-criteria {
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Calendar icon date picker */
.filter-date-wrap {
    position: relative;
    flex-shrink: 0;
}

.filter-date-hidden {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.filter-date-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    line-height: 1.2;
}

.filter-date-btn.has-value {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.filter-row-dates #typeFilter {
    flex: 1 1 0;
    min-width: 0;
    font-size: 0.85rem;
    padding: 0.5rem 0.45rem;
}

.filter-row-criteria #valueFilter,
.filter-row-criteria #criteriaFilter {
    min-width: 0;
    font-size: 0.85rem;
    padding: 0.5rem 0.45rem;
}

.filter-row-criteria .checkbox-label {
    flex: 0 0 auto;
    white-space: nowrap;
}

.filter-buttons {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.5rem;
    width: 100%;
}

.filter-buttons .btn {
    width: 100%;
    margin-top: 0;
    min-width: 0;
    min-height: 2.9rem;
    padding: 0.62rem 0.4rem;
    font-size: 1.15rem;
    line-height: 1;
    border-radius: 8px;
}

.filter-input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.1);
}

@media (max-width: 768px) {
    .track-header {
        align-items: stretch;
    }

    .track-actions,
    .filter-controls {
        width: 100%;
    }

    .filter-row {
        width: 100%;
    }

    .filter-row .filter-input {
        min-width: 0;
        max-width: 100%;
    }

    .filter-date-btn {
        font-size: 0.8rem;
        padding: 0.48rem 0.5rem;
    }

    .filter-row-dates #typeFilter,
    .filter-row-criteria #valueFilter,
    .filter-row-criteria #criteriaFilter {
        font-size: 0.82rem;
        padding: 0.48rem 0.4rem;
    }

    .filter-row .checkbox-label {
        flex: 0 0 auto;
    }

    .filter-row .checkbox-label span {
        white-space: normal;
    }

    .filter-buttons .btn {
        min-height: 2.75rem;
        padding: 0.58rem 0.35rem;
        font-size: 1.08rem;
    }
}

/* Daily Progress Bars */
#dailyProgressBars {
    display: grid;
    gap: 1.5rem;
}

.progress-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
    gap: 1rem;
}

.progress-label span:last-child {
    white-space: nowrap;
    text-align: right;
}

.progress-bar-container {
    background: var(--bg-primary);
    border-radius: 8px;
    height: 28px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35 0%, #FFB347 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    transition: width 0.3s ease;
    min-width: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.progress-bar.low {
    background: linear-gradient(90deg, #f44336 0%, #e91e63 100%);
}

.progress-bar.medium {
    background: linear-gradient(90deg, #FF9800 0%, #FFB347 100%);
}

.progress-bar.high {
    background: linear-gradient(90deg, #4CAF50 0%, #66BB6A 100%);
}

/* Mobile responsive for progress bars */
@media (max-width: 480px) {
    #dailyProgressBars {
        gap: 1rem;
    }

    .progress-item {
        gap: 0.4rem;
    }

    .progress-label {
        font-size: 0.85rem;
        gap: 0.75rem;
    }

    .progress-bar-container {
        height: 24px;
    }

    .progress-bar {
        font-size: 0.75rem;
    }
}


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

.track-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.track-table th,
.track-table td {
    padding: 0.85rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

.track-table th {
    color: var(--text-secondary);
    font-weight: 600;
}

.track-table tbody tr:hover {
    background: rgba(255, 107, 53, 0.05);
}

.track-table td {
    color: var(--text-primary);
}

.track-table td.action-cell {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.track-table td.action-cell .btn-small {
    margin: 0;
    min-width: 2rem;
    padding: 0.28rem 0.45rem;
}

/* Result Card */
.result-card {
    margin-top: 1rem;
    animation: slideDown 0.3s ease;
}

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

.result-content {
    padding: 0.5rem 0;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.result-row:last-child {
    border-bottom: none;
}

.result-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.result-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.05rem;
}

.result-value.highlight {
    font-size: 1.3rem;
    color: var(--primary-color);
}

.decision {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 12px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    animation: pulse 0.5s ease;
}

.decision.accept {
    background: rgba(76, 175, 80, 0.1);
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.decision.reject {
    background: rgba(244, 67, 54, 0.1);
    color: var(--reject-color);
    border: 2px solid var(--reject-color);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(255, 107, 53, 0.1);
}

/* Responsive Design */
@media (min-width: 768px) {
    .app-main {
        padding: 2rem;
    }
    
    .card {
        padding: 2rem;
    }
    
    .app-header h1 {
        font-size: 2.25rem;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .btn {
        padding: 1.25rem 1.5rem;
        font-size: 1.2rem;
    }

    .track-table td.action-cell .btn-small {
        padding: 0.3rem 0.45rem;
        font-size: 0.9rem;
    }
    
    .form-group input[type="number"],
    .form-group input[type="text"],
    .form-group input[type="password"],
    .form-group select {
        padding: 1.25rem;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --surface: #1e1e1e;
        --text-primary: #ffffff;
        --text-secondary: #b0b0b0;
        --border-color: #333333;
    }
}
