/* ---------------------------------------------------------
   GLOBAL RESET & BASE
--------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: Arial, sans-serif;
    background: #111;
    color: #e6e6e6;
    height: 100%;
    -webkit-font-smoothing: antialiased;
}

/* CRITICAL FIX: stop Safari shrinking text */
html {
    -webkit-text-size-adjust: 100% !important;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ---------------------------------------------------------
   PAGE LAYOUT
--------------------------------------------------------- */
.page {
    width: 100%;
    max-width: 1200px;
    margin: auto;
    padding: 16px;
}

.page-centered {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* ---------------------------------------------------------
   HEADER
--------------------------------------------------------- */
.page-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header-title h1 {
    font-size: 28px;
    font-weight: 600;
    margin: 0;
}

.page-header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin: 0;
}

.btn-exit {
    background: #007bff;
    color: white;
    border: none;
}

.btn-exit:hover {
    background: #0056b3;
}

/* ---------------------------------------------------------
   CARDS
--------------------------------------------------------- */
.card {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 0 12px rgba(0,0,0,0.4);
}

.card-full {
    width: 100%;
}

.card-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* Login card */
.card-auth {
    max-width: 380px;
    width: 100%;
}

/* ---------------------------------------------------------
   GRID LAYOUTS
--------------------------------------------------------- */
.page-main-grid {
    display: grid;
    gap: 20px;
}

@media (min-width: 700px) {
    .page-main-grid {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }
}

/* ---------------------------------------------------------
   FORM ELEMENTS
--------------------------------------------------------- */
.field-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 2px 0;
}

.field-label {
    font-size: 16px;
    opacity: 0.85;
    flex: 0 0 60%;
}

.field-input {
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #444;
    background: #222;
    color: #fff;
    font-size: 16px;
}

.field-input:focus {
    outline: none;
    border-color: #888;
}

/* ---------------------------------------------------------
   FIELD GRID (Dashboard values)
--------------------------------------------------------- */
.field-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px 0;
}

.field-row span.field-value {
    font-size: 18px;
    font-weight: 600;
    text-align: right;
}

/* ---------------------------------------------------------
   BUTTONS
--------------------------------------------------------- */
.btn {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
    border: none;
    text-align: center;
    display: inline-block;
    transition: background 0.2s;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: #0077ff;
    color: #fff;
}

.btn-primary:hover {
    background: #3392ff;
}

.btn-secondary {
    background: #333;
    color: #ddd;
}

.btn-secondary:hover {
    background: #444;
}

/* ---------------------------------------------------------
   ALERTS
--------------------------------------------------------- */
.alert {
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    font-size: 14px;
}

.alert-error {
    background: #661111;
    border: 1px solid #aa3333;
    color: #ffcccc;
}

/* ---------------------------------------------------------
   BRANDING (Login page)
--------------------------------------------------------- */
.brand-block {
    text-align: center;
    margin-bottom: 10px;
}

.brand-title {
    font-size: 24px;
    font-weight: 600;
}

.brand-subtitle {
    opacity: 0.8;
    margin-top: 4px;
}

.brand-image img {
    width: 100%;
    border-radius: 6px;
    margin: 10px 0 20px 0;
}

/* ---------------------------------------------------------
   SPACING UTILITIES
--------------------------------------------------------- */
.mt-8  { margin-top: 8px;  }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }

/* ---------------------------------------------------------
   TUYA DEVICE CARDS
--------------------------------------------------------- */
.tuya-device {
    padding: 16px;
}

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

/* ---------------------------------------------------------
   SENSOR BLOCKS
--------------------------------------------------------- */
.th-block {
    background: #222;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 6px;
}

.th-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

/* ---------------------------------------------------------
   DP LIST
--------------------------------------------------------- */
.dp-container {
    margin-top: 12px;
}

.dp-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #333;
    font-size: 13px;
}

.dp-row span {
    flex: 1;
}

/* ---------------------------------------------------------
   RANGE INPUTS (Bulb controls)
--------------------------------------------------------- */
input[type="range"] {
    width: 100%;
}

input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 4px;
}

/* ---------------------------------------------------------
   MOBILE FONT OPTIMISATION (general small screens)
--------------------------------------------------------- */
@media (max-width: 600px) {

    .card-title {
        font-size: 20px;
    }

    .field-label {
        font-size: 16px;
    }

    .field-value {
        font-size: 18px;
    }

    .card {
        padding: 12px;
    }

    .field-row {
        margin-bottom: 6px;
        padding: 2px 0;
    }

    .page-header-title h1 {
        font-size: 24px;
    }

    .btn {
        font-size: 16px;
        padding: 10px 14px;
    }
}

/* ---------------------------------------------------------
   iPHONE SE PORTRAIT — FINAL FIX
--------------------------------------------------------- */
@media screen and (max-width: 380px) and (orientation: portrait) {

    html {
        -webkit-text-size-adjust: none !important;
        font-size: 18px !important;
    }

    .card-title {
        font-size: 22px !important;
    }

    .field-label {
        font-size: 18px !important;
    }

    .field-value {
        font-size: 20px !important;
    }

    .card {
        padding: 14px !important;
    }

    .page-header-title h1 {
        font-size: 26px !important;
    }

    .btn {
        font-size: 18px !important;
        padding: 12px 16px !important;
    }
}

.field-input {
    width: 100%;
    max-width: 100%;
}
