/* ============================================
   TEMA SİSTEMİ - Dark & Light Mode
   ============================================ */

/* Dark Mode (Varsayılan) */
:root,
[data-theme="dark"] {
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --bg-input: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --error-color: #cf6679;
    --success-color: #00e676;
    --border-color: #333;
    --shadow: rgba(0, 0, 0, 0.3);
    --hover-bg: rgba(255, 255, 255, 0.02);
    --font-family: 'Inter', sans-serif;
}

/* Light Mode */
[data-theme="light"] {
    --bg-dark: #f5f5f5;
    --bg-card: #ffffff;
    --bg-input: #f9f9f9;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --primary-color: #6200ea;
    --secondary-color: #00897b;
    --error-color: #c62828;
    --success-color: #2e7d32;
    --border-color: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
    --hover-bg: rgba(0, 0, 0, 0.02);
    --font-family: 'Inter', sans-serif;
}

/* Tema geçiş animasyonu */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Prevent horizontal scroll on mobile */
    overflow-x: hidden;
    /* Better text rendering on mobile */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
    /* Better tap targets on mobile */
    -webkit-tap-highlight-color: rgba(187, 134, 252, 0.2);
}

a:hover {
    color: #9965f4;
}

/* Layout */
.navbar {
    background-color: var(--bg-card);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-color);
    letter-spacing: 1px;
}

.navbar-menu a {
    margin-left: 20px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.navbar-menu a:hover,
.navbar-menu a.active {
    color: var(--primary-color);
}

.navbar-toggle {
    display: none;
}

.nav-mobile-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.container {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 2rem;
    width: 100%;
    display: block;
}

/* Wide container for pages with many columns (inventory, stock detail, etc.) */
.container-wide {
    max-width: 98%;
    margin: 2rem auto;
    padding: 0 1rem;
    width: 100%;
    flex: 1;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    /* Better mobile input handling */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.2);
}

/* Better select styling for mobile */
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='%23a0a0a0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

button,
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    display: inline-block;
    text-align: center;
    /* Better tap targets */
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:hover {
    background-color: #a370f7;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-secondary:hover {
    background-color: rgba(187, 134, 252, 0.1);
}

.btn-danger {
    background-color: var(--error-color);
    color: #fff;
}

.btn-danger:hover {
    background-color: #b05565;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
    margin: 0 -1rem;
    /* Extend to edges on mobile */
    padding: 0 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    min-width: 600px;
    /* Prevent table from being too narrow */
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    /* Prevent text wrapping in cells */
}

th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background-color: var(--bg-card);
    z-index: 10;
}

tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-pending {
    background-color: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

.badge-in_progress {
    background-color: rgba(3, 218, 198, 0.2);
    color: var(--secondary-color);
}

.badge-completed {
    background-color: rgba(0, 230, 118, 0.2);
    color: var(--success-color);
}

/* Login Page Spec */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
}

.login-title {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 2rem;
    color: var(--primary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* ============================================
   MOBILE RESPONSIVE DESIGN
   Optimized for both Android and iOS devices
   ============================================ */

/* Tablet Breakpoint */
@media (max-width: 992px) {
    .container {
        padding: 0 1.5rem;
    }

    .card {
        padding: 1.5rem;
    }

    table {
        font-size: 0.9rem;
    }

    th,
    td {
        padding: 0.75rem;
    }
}

/* Mobile Breakpoint */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    .navbar {
        flex-direction: column;
        padding: 1rem;
        gap: 0;
        align-items: stretch;
    }

    .nav-mobile-header {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        position: relative;
        padding: 0.5rem 0;
    }

    .navbar-brand {
        margin-right: 0;
        font-size: 1.25rem;
    }

    .navbar-brand img {
        height: 40px !important;
        transition: height 0.3s ease;
    }

    /* Navbar Toggle Button */
    .navbar-toggle {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        background: transparent;
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
        border-radius: 6px;
        cursor: pointer;
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        min-height: 44px;
        /* iOS tap target */
    }

    .navbar-toggle:hover,
    .navbar-toggle:active {
        background: rgba(255, 255, 255, 0.1);
    }

    .navbar-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        margin-top: 1rem;
        animation: fadeIn 0.3s ease-out;
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-menu a {
        margin-left: 0;
        width: 100%;
        text-align: center;
        padding: 0.75rem;
        background-color: #2d2d2d;
        border-radius: 6px;
        border: 1px solid transparent;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .navbar-menu a:hover,
    .navbar-menu a:active {
        border-color: var(--primary-color);
        background-color: #333;
    }

    .navbar-menu .btn {
        margin-left: 0 !important;
        width: 100%;
    }

    .container {
        padding: 0 1rem;
        margin: 1rem auto;
    }

    .card {
        padding: 1rem;
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        align-items: stretch;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .card-header .btn {
        width: 100%;
    }

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

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px;
        /* Prevent iOS auto-zoom */
        padding: 0.875rem;
        min-height: 44px;
        /* iOS tap target */
    }

    /* IMPORTANT: Radio and Checkbox groups MUST stay horizontal */
    .radio-group,
    .checkbox-group {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 1rem !important;
    }

    .radio-group label,
    .checkbox-group label {
        display: inline-flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        width: auto !important;
        min-width: auto !important;
        flex: 0 0 auto !important;
        cursor: pointer;
    }

    /* Stack OTHER flex containers (not radio/checkbox groups) */
    form>div[style*="display: flex"]:not(.radio-group):not(.checkbox-group),
    form>div[style*="display:flex"]:not(.radio-group):not(.checkbox-group),
    form div[style*="display: flex"]:not(.radio-group):not(.checkbox-group):not([class*="checkbox"]):not([class*="radio"]),
    form div[style*="display:flex"]:not(.radio-group):not(.checkbox-group):not([class*="checkbox"]):not([class*="radio"]) {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    /* Children of stacked containers should be full width */
    form>div[style*="display: flex"]:not(.radio-group):not(.checkbox-group)>div:not(label),
    form>div[style*="display:flex"]:not(.radio-group):not(.checkbox-group)>div:not(label) {
        width: 100% !important;
        min-width: 100% !important;
        flex: none !important;
    }

    /* Labels in flex containers (not in radio/checkbox groups) */
    form>div[style*="display: flex"]:not(.radio-group):not(.checkbox-group)>label,
    form>div[style*="display:flex"]:not(.radio-group):not(.checkbox-group)>label {
        width: auto !important;
        min-width: auto !important;
        flex: 0 0 auto !important;
        margin-right: 1rem;
    }

    /* Grid layouts to single column */
    div[style*="display: grid"],
    div[style*="display:grid"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Flex space-between to column */
    div[style*="justify-content: space-between"],
    div[style*="justify-content:space-between"] {
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: stretch !important;
        text-align: center;
    }

    div[style*="justify-content: space-between"] .btn,
    div[style*="justify-content:space-between"] .btn {
        width: 100%;
        margin-left: 0 !important;
    }

    /* Login Page */
    .login-container {
        margin: 2rem 1rem;
        width: auto;
    }

    .login-title {
        font-size: 1.5rem;
    }

    /* Table improvements for mobile */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0;
        border-radius: 0;
    }

    table {
        font-size: 0.85rem;
        min-width: 500px;
    }

    th,
    td {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    th {
        font-size: 0.75rem;
    }

    /* Better button sizing on mobile */
    .btn {
        padding: 0.875rem 1.25rem;
        font-size: 0.95rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Inline buttons in tables */
    td .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        width: auto;
        margin-bottom: 0;
        white-space: nowrap;
    }

    /* Footer */
    footer {
        padding: 1.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    .navbar-brand {
        font-size: 1.1rem;
    }

    .navbar-brand img {
        height: 32px !important;
    }

    .navbar-toggle {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }

    .card {
        padding: 0.875rem;
    }

    .card-title {
        font-size: 1rem;
    }

    table {
        min-width: 400px;
        font-size: 0.8rem;
    }

    th,
    td {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    th {
        font-size: 0.7rem;
    }

    .btn {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }

    td .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {

    /* iOS Safari */
    input,
    select,
    textarea {
        font-size: 16px !important;
        /* Prevent zoom on focus */
    }

    /* Fix iOS button rendering */
    button,
    .btn {
        -webkit-appearance: none;
        appearance: none;
        cursor: pointer;
    }

    /* Smooth scrolling */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}

/* Android Specific Fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {

    /* Android Chrome */
    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='%23a0a0a0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    }
}

/* Landscape Mode Optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        margin: 0.5rem auto;
    }

    .card {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }

    .navbar {
        padding: 0.5rem 1rem;
    }

    .navbar-brand img {
        height: 32px !important;
    }
}

/* High DPI Displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Dark Mode Support (for devices with dark mode preference) */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but can add overrides if needed */
}

/* Reduced Motion Support (Accessibility) */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}