/* --- COMMON / SHARED STYLES --- */

/* RESET & GLOBAL */
* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-body);
    color: var(--text-main);
    margin: 0;
}

h1, h2, h3, h4 {
    color: var(--theme-color);
    margin-top: 0;
}

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

/* UTILITY HELPERS */
.text-main { color: var(--text-main); }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-theme { color: var(--theme-color); }

/* FORMS & INPUTS */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
input[type="file"],
input[type="color"],
textarea,
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-main);
    box-sizing: border-box;
    transition: border-color 0.2s;
    height: auto;
    min-height: 48px; /* Taller for accessibility/touch */
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--theme-color);
}

button,
.btn {
    padding: 0.75rem 1.5rem;
    background: var(--theme-color);
    color: var(--theme-text);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    transition: filter 0.2s;
    display: inline-block;
    text-align: center;
    white-space: nowrap;
}

button:hover,
.btn:hover {
    filter: brightness(1.1);
}

button:disabled {
    background: var(--text-dim);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--theme-color);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    background: var(--bg-hover);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-sm:hover {
    border-color: var(--theme-color);
    color: var(--theme-color);
}

/* ALERTS */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-error {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid #ff4757;
    color: #ff4757;
}

.alert-success {
    background: rgba(46, 213, 115, 0.1);
    border: 1px solid #2ed573;
    color: #2ed573;
}

/* TOASTS (Shared because JS is global) */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 1rem;
    border-radius: 4px;
    border-left: 4px solid var(--theme-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    max-width: 90vw;
    pointer-events: auto;
    animation: slideIn 0.3s ease-out;
    position: relative;
    font-size: 0.95rem;
}

.toast a {
    color: var(--theme-color);
}

.toast.toast-error {
    border-left-color: #ff4757;
}

.toast.toast-success {
    border-left-color: #2ed573;
}

.toast-close {
    position: absolute;
    top: 5px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ============================================
   ACCESSIBILITY & KEYBOARD NAVIGATION
   ============================================ */

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--theme-color);
    color: var(--theme-text);
    padding: 0.75rem 1.5rem;
    z-index: 10000;
    border-radius: 0 0 4px 0;
    font-weight: bold;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* Enhanced focus states for keyboard navigation */
button:focus-visible,
.btn:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--theme-color);
    outline-offset: 2px;
}

/* Remove outline for mouse users but keep for keyboard */
button:focus:not(:focus-visible),
.btn:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible but not position changed */
.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   TOUCH-FRIENDLY CONTROLS
   ============================================ */

/* Minimum touch target size (44px recommended by WCAG) */
@media (pointer: coarse) {
    button,
    .btn,
    .nav-link,
    .tab-btn,
    a.button {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1rem;
    }
    
    /* Larger checkboxes and radio buttons on touch */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 8px;
    }
    
    /* More spacing between clickable items */
    .nav-link,
    .tab-btn {
        margin-bottom: 4px;
    }
}

/* Improved tap highlight on mobile */
@media (max-width: 768px) {
    button,
    .btn,
    a {
        -webkit-tap-highlight-color: rgba(var(--theme-color-rgb, 128, 90, 213), 0.2);
    }
}
