/* =========================================
   1. Base & Reset
   ========================================= */
* {
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
    font-size: 18px; /* Default: Tablet/iPad optimized */
    line-height: 1.6;
}

h1, h2, h3 {
    color: #333;
    margin-top: 0;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

a {
    color: #003366;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* =========================================
   2. Layout & Containers
   ========================================= */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: #fff;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 250px;
    background: #333;
    color: #fff;
    padding: 20px;
    box-sizing: border-box;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.admin-sidebar a {
    display: block;
    color: #ddd;
    text-decoration: none;
    padding: 12px 15px;
    border-bottom: 1px solid #444;
}

.admin-sidebar a:hover {
    color: #fff;
    background-color: #444;
    padding-left: 20px;
}

.admin-sidebar a.active {
    background-color: var(--color-dashboard-group-app, #fff3e0);
    color: var(--color-app-text, #333);
}

.admin-content {
    flex: 1;
    padding: 20px;
    background: #f9f9f9;
    width: 100%;
    overflow-x: auto;
}

.admin-sidebar-toggle {
    display: none;
    background: #333;
    color: #fff;
    border: none;
    padding: 10px;
    font-size: 20px;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.flex-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.flex-col {
    flex: 1;
    min-width: 200px; /* Prevent crushing on small screens */
}

.flex-fixed-100 {
    flex: 0 0 100px;
}

.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.p-10 { padding: 10px; }
.p-15 { padding: 15px; }

.bg-light { background-color: #eee; }
.bg-white { background-color: #fff; }
.radius-5 { border-radius: 5px; }

/* =========================================
   3. Forms
   ========================================= */
/* Hide spin buttons for numbers */
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
}

form {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], select {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    box-sizing: border-box;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.checkbox-group input {
    width: auto;
    margin: 0;
}

.checkbox-group label {
    margin: 0;
    font-weight: normal;
}

/* =========================================
   4. Buttons
   ========================================= */
.btn {
    display: inline-block;
    padding: 12px 20px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    color: white;
    text-align: center;
    line-height: 1.5;
    vertical-align: middle;
    transition: background-color 0.2s;
}

.btn-block {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

.btn-primary { background-color: #5cb85c; }
.btn-primary:hover { filter: brightness(90%); }

.btn-success { background-color: #28a745; }
.btn-success:hover { filter: brightness(90%); }

.btn-secondary { background-color: #777; }
.btn-secondary:hover { filter: brightness(90%); }

.btn-danger { background-color: #d9534f; }
.btn-danger:hover { filter: brightness(90%); }

.btn-warning { background-color: #f0ad4e; }
.btn-warning:hover { filter: brightness(90%); }

.logout { float: right; }

/* =========================================
   5. Tables & Lists
   ========================================= */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 12px;
    border: 1px solid #ddd;
    text-align: left;
}

th {
    background-color: #f2f2f2;
    font-weight: bold;
}

tr.active-row { background-color: #e8f5e9; }
tr.inactive-row { background-color: #f9f9f9; color: #999; }

th.sortable { cursor: pointer; }
th.sortable a { display: block; width: 100%; height: 100%; color: inherit; }
th.sortable:hover { background-color: #e9e9e9; }

/* =========================================
   6. Alerts & Status
   ========================================= */
.alert {
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}
.alert-success { background-color: #d4edda; color: #155724; }
.alert-warning { background-color: #fff3cd; color: #856404; }
.error { color: red; }
.text-danger { color: #d9534f; }
.text-success { color: #28a745; }
.text-muted { color: #6c757d; font-size: 0.9em; }

/* Status Cards (Settings) */
.status-card-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.status-card {
    background: #f9f9f9;
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    flex: 1;
    min-width: 150px;
}
.status-card .label { font-size: 1rem; color: #555; display: block; margin-bottom: 5px; }
.status-card .value { font-size: 2.5rem; font-weight: bold; color: #333; }
.status-card.warning { border-color: #d9534f; background-color: #fff5f5; }
.status-card.success { border-color: #5cb85c; background-color: #f0fff4; }

/* Dynamic Status Colors */
.status-bg-red { background-color: #d9534f !important; color: #ffffff !important; }
.status-bg-red .label, .status-bg-red .value { color: #ffffff !important; }

.status-bg-orange { background-color: #f0ad4e !important; color: #000000 !important; }
.status-bg-orange .label, .status-bg-orange .value { color: #000000 !important; }

.status-bg-green { background-color: #ffffff !important; color: #5cb85c !important; border-color: #5cb85c !important; }
.status-bg-green .label { color: #555 !important; }
.status-bg-green .value { color: #5cb85c !important; }


/* =========================================
   7. Media Queries
   ========================================= */

/* Smartphone (Portrait/Small Screens) */
@media (max-width: 768px) {
    body {
        padding: 10px;
        font-size: 16px; /* Smaller base font for mobile */
    }

    .container {
        padding: 15px;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Stack flex containers */
    .flex-row {
        flex-direction: column;
        gap: 10px;
    }

    .flex-col, .flex-fixed-100 {
        width: 100%;
        flex: auto;
    }

    /* Full width buttons on mobile */
    .btn {
        width: 100%;
        margin-bottom: 5px;
        box-sizing: border-box;
        white-space: normal; /* Allow text wrapping on multiple lines */
        height: auto;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    /* Table adjustments */
    th, td {
        padding: 8px;
        font-size: 0.9rem;
    }

    .status-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .status-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 10px; /* Reduced padding */
    }

    .status-card .label {
        font-size: 0.8rem; /* Smaller font */
        height: auto;
        margin-bottom: 5px;
        line-height: 1.2;
    }

    .status-card .value {
        font-size: 1.5rem; /* Smaller value font */
        word-break: break-word;
    }

    /* Specific height adjustment for card row items on mobile */
    .status-card-container .status-card {
        min-height: 80px; /* Approximately 70% of desktop/default height */
    }

    /* Sidebar Tweaks for Mobile */
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        height: auto;
        min-height: auto;
        display: none;
        padding: 10px;
    }

    .admin-sidebar.show {
        display: block !important;
    }

    .admin-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px;
        background: #333;
        color: white;
    }

    .mobile-logo {
        max-height: 40px;
        margin-right: 10px;
    }

    .admin-sidebar-toggle {
        display: block;
        width: auto;
        padding: 5px 10px;
        background: none;
        border: 1px solid #555;
    }

    .sidebar-group-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 10px;
    }

    .sidebar-group-grid a {
        border: 1px solid #555;
        border-radius: 4px;
        text-align: center;
        padding: 15px 5px;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Mobile Sidebar Buttons - Contrast adjustment */
    .sidebar-group-match .sidebar-group-grid a {
        background-color: var(--color-match-btn) !important;
        color: var(--color-match-btn-text) !important;
        border-color: var(--color-match-text) !important; /* Border matches group text color for visibility */
    }

    .sidebar-group-app .sidebar-group-grid a,
    .sidebar-group-app a {
        background-color: var(--color-app-btn) !important;
        color: var(--color-app-btn-text) !important;
        border-color: var(--color-app-text) !important;
    }

    /* Mobile Active Links - White background override */
    .sidebar-group-match .sidebar-group-grid a.active,
    .sidebar-group-app .sidebar-group-grid a.active,
    .sidebar-group-app a.active {
        background-color: #ffffff !important;
        color: #333333 !important;
        font-weight: bold !important;
        border-color: #cccccc !important;
    }

    /* Ensure settings footer buttons are full width and stacked */
    form button[type="submit"], form a.btn-secondary {
        width: 100%;
        margin-left: 0 !important;
        margin-bottom: 10px;
        display: block;
    }

    .mobile-only { display: block; }
    .desktop-only { display: none; }
}

/* Tablet / Desktop Defaults */
@media (min-width: 769px) {
    .mobile-only { display: none; }
    .desktop-only { display: block; }
    .admin-sidebar { display: block !important; }
}

/* Specific Admin Styles */
.admin-layout {
    display: flex;
    min-height: 100vh;
}
.admin-sidebar {
    width: 250px;
    background: #333;
    color: #fff;
    padding: 20px;
    box-sizing: border-box;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}
.admin-sidebar-toggle {
    display: none;
    background: #333;
    color: #fff;
    border: none;
    padding: 10px;
    font-size: 20px;
    cursor: pointer;
    width: 100%;
    text-align: left;
}
.admin-sidebar a {
    display: block;
    color: #ddd;
    text-decoration: none;
    padding: 12px 15px;
    border-bottom: 1px solid #444;
}
.admin-sidebar a:hover {
    color: #fff;
    background-color: #444;
    padding-left: 20px;
}
.admin-sidebar a.active {
    color: #fff;
    background-color: #555;
    font-weight: bold;
}

/* Dashboard styling override */
.admin-sidebar a.dashboard-link.active {
    background-color: var(--color-dashboard-group-app, #fff3e0);
    color: #333;
}

/* Group Active Links Override */
.sidebar-group-match a.active,
.sidebar-group-app a.active {
    background-color: #ffffff;
    color: #333;
    font-weight: bold;
}

.sidebar-group {
    border-top: 1px solid #555;
    border-bottom: 1px solid #555;
    margin: 10px 0;
    padding: 10px 0;
    background-color: rgba(255,255,255,0.05);
}

.admin-content {
    flex: 1;
    padding: 20px;
    background: #f9f9f9;
    width: 100%; /* Ensure content takes full width on small screens */
    overflow-x: auto; /* Prevent scroll overflow */
}
.login-logo {
    max-width: 200px;
    margin: 0 auto 20px;
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    .admin-sidebar {
        width: 100%;
        height: auto;
        min-height: auto;
        display: none; /* Hidden by default on mobile */
    }
    .admin-sidebar.show {
        display: block;
    }
    .admin-sidebar-toggle {
        display: block;
    }
}

/* Desktop / Large Screens (Computer/TV) */
@media (min-width: 1200px) {
    body {
        font-size: 13px;
        background-color: #e9ecef;
    }

    .container {
        max-width: 1200px;
        padding: 40px;
    }

    input[type="text"], input[type="password"], input[type="number"], select {
        padding: 10px; /* Reduced padding */
        font-size: 1rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 1rem;
    }

    h2 {
        font-size: 1.2rem;
    }

    h3 {
        font-size: 1rem;
    }

    .status-card .value {
        font-size: 2rem;
    }

    .grid-2-col {
        grid-template-columns: 1fr 1fr;
    }
}

/* Logo Link Override - No Hover Effect */
a.logo-link {
    background-color: transparent !important;
    padding: 0 !important;
    border: none !important;
    margin: 0 !important;
}

a.logo-link:hover {
    background-color: transparent !important;
    padding-left: 0 !important;
    text-decoration: none !important;
    cursor: pointer;
}
